I am new to C#, Windows Forms, and datagridviews. I have a tabbed form: tab 1 displays a datagridview of the exercises table; tab 2 is for adding a new exercise to the table. Th
You have to reload your Dataset with the information from the database after doing the insert. It's not automatic!
Create a LoadDataGridView method:
private void LoadDataGridView() {
// Fill a DataAdapter using the SelectCommand.
DataAdapter da = null;
// The Sql code here
// In case something fails, bail out of the method.
if (da == null) return;
// Clear the DataSource or else you'll get double of everything.
if (exerciseListDataGridView.DataSource != null) {
exerciseListDataGridView.DataSource.Clear();
exerciseListDataGridView.DataSource = null;
}
// I'm doing this off the top of my head, you may need to fill a DataSet here.
exerciseListDataGridView.DataSource = da.DefaultView;
}
Now all you have to do is call that method in both your Form1_Load() and at the end of your InsertExcercise(). If you have to use a DataSet, don't forget to dispose of the DataAdapter object at the end to conserve resources.