C# – unable to add new row using datagridview using C# in Winforms

cdatagridviewwinforms

i wanted to make a simple data entry application. So i did the following

  • Created a new Windows Form Application
  • Added a DataGridView
  • Added a new DataSource (SQL Express Database, having a single table with 3 columns – id, name, number) id is integer and is the primary key
  • As the designer automatically populates the DataSet, BindingSource and TableAdapter i ran the application.

when i ran the application it showed the existing data, and i was able to add new data by clicking on empty row or edit existing data. But it did not store (commit) the data for me.

After i make the changes i just close the application. I remember doing it some time ago and it used to reflect changes. Do i have to add any code to commit the changes?

Best Answer

A dataset is (by definition) disconnected. If you want to commit new data / updates / deletes (etc), you are going to have to ask the adapter to save the changes. If you already have a generated adapter, this should be about 1 line of extra code... (Update on the adapter, usually via a save button's Click handler).

Related Topic