Hello,
I posted yesterday regarding my issues with adding rows to a database, this is now solved and I am grateful. Once the rows were added to the database the list box that displays one column of the database did not update so I included the following code after the addition had been made:
cnn.ConnectionString = "Data Source=FYPSERVER;Initial Catalog=FYP;Integrated Security=True";
cnn.Open();
da.Fill(fypDataSet, "category");
cnn.Close();
I assume this refilled the data adapter with the updated information and it worked, my list box and its values were updated.
However the same bit of code does not work after I delete a value from the database.
Here is my code:
delCat(lstCategories.Text); //this deletes the value from the database
lstCategories.SelectedIndex = -1;
cnn.ConnectionString = "Data Source=FYPSERVER;Initial Catalog=FYP;Integrated Security=True";
cnn.Open();
da.Fill(fypDataSet, "category");
cnn.Close();
The row is deleted from the database but it is not removed from the list box. If I close the form and re-open then the values are updated but they don't change until then, which is not very ideal.
I have done some seraching on here and in google but nothing made a difference.
I have tried the following but I don't really have a clue what I am doing:
lstCategories.Refresh(),
categoryBindingSource.ResetBindings(false), and
categoryBindingSource.ResetBindings(true).
I am using Visual Studio 2010 ultimate.
Thank you