Same as the title and using C#. Anyone know how to do this? I have a bunch of data read into a list box but the data doesn't refresh unless I restart the windows form. anyone know how to refresh it on a button click event?
{
SqlConnection conn = new SqlConnection();
conn.ConnectionString = (@"Data Source=.\SQLEXPRESS;AttachDbFilename=C:\Users\John\Desktop\DB\DB\DB\setup.mdf;Integrated Security=True;Connect Timeout=30;User Instance=True");
conn.Open();
SqlCommand cmd = new SqlCommand
("SELECT PEOPLE " + "FROM Workers", conn);
try
{
SqlDataReader sdr = cmd.ExecuteReader();
while (sdr.Read())
{
listBox1.Items.Add(sdr["people"].ToString());
}
sdr.Close();
}
catch (SqlException ex)
{
MessageBox.Show(ex.Message);
}
finally
{
conn.Close();
}
}
This is in windows form Load. So i'm looking to add a button on my form which refreshes the listbox items list