I wrote a simple C # prog using ADO.NET elements.
From the Access database ("mdb" format), the "OleDbDataAdapter" class pulled data for a specific table and "stuffed" it into the "DataGridView" object, created a BindingSource and a BindingNavigator for managing records. There was a problem with saving the data after changing it in the DataGridView - the data does not want to be written to the database.
I give a snippet of code:

... private DataSet mainDS; ... private void MakeTable(string tableName) { //подключение и вытаскивание данных OleDbConnection cn = new OleDbConnection(); cn.ConnectionString = "Provider=Microsoft.Jet.OLEDB.4.0;" + @"Data Source= D:\KP\main.mdb;"; cn.Open(); OleDbDataAdapter dAdapt = new OleDbDataAdapter("SELECT * FROM " + tableName, cn); mainDS = new DataSet("main"); dAdapt.Fill(mainDS, tableName); cn.Close();  //тут наверно и ошибка resGrid.DataSource = mainDS.Tables[tableName]; resGrid.Refresh(); bindingSource1.DataSource = resGrid.DataSource; bindingNavigator1.BindingSource = bindingSource1; 

 ... private DataSet mainDS; ... private void MakeTable(string tableName) { //подключение и вытаскивание данных OleDbConnection cn = new OleDbConnection(); cn.ConnectionString = "Provider=Microsoft.Jet.OLEDB.4.0;" + @"Data Source= D:\KP\main.mdb;"; cn.Open(); OleDbDataAdapter dAdapt = new OleDbDataAdapter("SELECT * FROM " + tableName, cn); mainDS = new DataSet("main"); dAdapt.Fill(mainDS, tableName); cn.Close();  //тут наверно и ошибка resGrid.DataSource = mainDS.Tables[tableName]; resGrid.Refresh(); bindingSource1.DataSource = resGrid.DataSource; bindingNavigator1.BindingSource = bindingSource1; 

}

Help please, it is very necessary! Thank you in advance!
Py.Sy: added a button to bindingNavigator1 that executes the code: "mainDS.AcceptChanges ();" and still does not plow - (

  • The question is relevant. Help pls. - uzumaxy
  • Up! I really need your help! "It will be for me to go through the grid and see which records have been changed, and then indicate in the Update for the adapter?" - uzumaxy
  • "1.0k hits", "set 12 hours ago", "answered 12 hours ago". What is it like? - Vladimir Gordeev

1 answer 1

DataSet.AcceptChanges marks data as unchanged.

To save the data, you need to call the adapter Update. At the same time, for all unsaved changes, the database update commands will be generated. Accordingly, if AcceptChanges is called before this, nothing will be saved in the database either.

  • It will be for me to go through the grid and see which records have been changed, and then indicate in the Update for the adapter? - uzumaxy
  • AcceptChanges removed. - uzumaxy
  • one
    No, the adapter will do it. It is necessary to call Update once for the whole DataTable - Modus