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