Failed to add new row using datagridview using C # in Winforms

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

  • New Windows Form Application Created
  • Added DataGridView
  • Added a new DataSource (SQL Express database that has one table with three columns - id, name, number) id is an integer and is the main key
  • When the developer automatically populates the DataSet, BindingSource and TableAdapter, I started the application.

when I started the application, it showed the existing data, and I was able to add new data by clicking on an empty line or editing existing data. But he did not store the data for me.

After making the changes, I just close the application. I remember how this was done some time ago, and it reflected the changes. Do I need to add code to commit changes?

+3
source share
2 answers

The data set (by definition) is disabled. If you want to commit new data / updates / deletes (etc.), you will have to ask the adapter to save the changes. If you already have a generated adapter, this should be about 1 line of additional code ... ( Updateon the adapter, usually via the save button Click).

+2
source

Source: https://habr.com/ru/post/1711991/


All Articles