Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 9233711
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 18, 20262026-06-18T06:37:11+00:00 2026-06-18T06:37:11+00:00

I have a ListView and the ListView data is taken from database. Beside the

  • 0

I have a ListView and the ListView data is taken from database.
Beside the ListView got a button to add the record.

if the button is pressed it will show a dialog

Code :

private void bAddStudent_Click(object sender, EventArgs e) {
    fAddStudent addStudent = new fAddStudent();
    addStudent.ShowDialog();
}

After add the record, the dialog will close() and show the ListView.
But the ListView is not update the data.

Is there any way to make it auto update?

Edit :
Here is how I add records :

private void btnAdd_Click(object sender, EventArgs e) {
    string studentID = tbStudentId.Text;
    string studentName = tbStudentName.Text;
    string gender = tbGender.Text;

    string connectionString = "Data Source=xxx\\SQLEXPRESS;Initial Catalog=TestApplication;Integrated Security=SSPI; User ID=xxx;Password=xxx";

    using (SqlConnection connection = new SqlConnection(connectionString)) {
        SqlCommand cmd = new SqlCommand("INSERT INTO student (student_id, student_name, student_gender) VALUES (@studentId, @studentname, @studentGender) ");
        cmd.CommandType = CommandType.Text;
        cmd.Connection = connection;
        cmd.Parameters.AddWithValue("@studentId", studentID);
        cmd.Parameters.AddWithValue("@studentName", studentName);
        cmd.Parameters.AddWithValue("@studentGender", gender);
        connection.Open();
        cmd.ExecuteNonQuery();
    }
}

Code For showing ListView :

List<string> myListHeader = new List<string>(new string[] { "ID", "Name", "Gender" });
myListHeader.ForEach(name => lvStudent.Columns.Add(name));

SqlConnection UGIcon = new SqlConnection();
UGIcon.ConnectionString = "Data Source=xxx\\SQLEXPRESS;Initial Catalog=TestApplication;Integrated Security=SSPI; User ID=xxx\\user;Password=xxx";
UGIcon.Open();

SqlCommand cmd = new SqlCommand("SELECT * FROM student", UGIcon);

SqlDataReader dr = cmd.ExecuteReader();
while (dr.Read()) {
    ListViewItem item = new ListViewItem(dr[0].ToString());
    item.SubItems.Add(dr[1].ToString());
    item.SubItems.Add(dr[2].ToString());
    lvStudent.Items.Add(item);
}

Note

‘Add data’ form is different with showing the ListView form, so I cannot access the ListView in the ‘add data’ form

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-18T06:37:12+00:00Added an answer on June 18, 2026 at 6:37 am

    You need to call databind() method every time you want your data to be refreshed.

    From what I understood you a)show the data, b) add new record to database but new record is not shown. If this is the case just call DataBind() method and it should work.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

i have a listview that shows diferent data from my database. this works perfeclty.
I have ListView which is saving all data to database. For adding i have
I have dynamic listview on my android client app that receive data from remote
I have a listview, baseadapter and data from SQLite, including a BLOB. What if
I have written some thing like this to fetch data from the database. public
I have a listview that's populated by rows that get their data from a
I have a ListView and a EditText . How can I filter ListView data
I have ListView that uses a GridView to display several columns of data. Two
I have a listview that I'm populating with data and I'm trying to get
I have a custom listview, i successfully parse the data into a list but

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.