Loading of the table comes from access, I display it in gridView.

Preservation:

connection.Open(); // перебор всех строк dataGridView и присваивание dataSet-у for (int i = 0; i < dataSetPlayerSkill.Tables[0].Rows.Count; i++) { for (int j = 0; j < dataSetPlayerSkill.Tables[0].Rows[0].ItemArray.Length; j++) dataSetPlayerSkill.Tables[0].Rows[i].ItemArray[j] = dataGridViewPlayerSkill.Rows[i].Cells[j].Value; } dataSetPlayerSkill.AcceptChanges(); adapter.SelectCommand = commandPlayerSkill; adapter.UpdateCommand = new OleDbCommand("UPDATE PlayerSkill SET [Поле1] = 3,[Поле2] = 3,[Поле3] = 3,[Поле4] = 3 WHERE [Код] = 1;", connection); adapter.Update(dataSetPlayerSkill); adapter.UpdateCommand = new OleDbCommand("UPDATE PlayerSkill SET [Поле1] = 3,[Поле2] = 3,[Поле3] = 3,[Поле4] = 3 WHERE [Код] = 2;", connection); adapter.Update(dataSetPlayerSkill); dataSetPlayerSkill.AcceptChanges(); connection.Close(); 

Changes are saved if the cell is changed manually (double click on the cell and entering the value), but if the cell is changed by the program (dataGridView2.Rows [0] .Cells [j] .Value = 2), then the database does not save changes

In addition, only 1 query (sql update) is saved, the above shows an example that out of two or more update only the first row is saved on different lines

Ads:

  string tableNamePlayerSkill; string tableNameMain; string dataBasePath; string dataBaseName; double[][] matrixFirst; double[][] matrixAlternativ; OleDbConnection connection; OleDbDataAdapter adapter; OleDbCommand commandPlayerSkill; OleDbCommand commandMain; DataSet dataSetMain; DataSet dataSetPlayerSkill; 

Loading:

  // Таблица PlayerSkill connection.Open(); adapter.SelectCommand = commandPlayerSkill; dataSetPlayerSkill = new DataSet(); adapter.Fill(dataSetPlayerSkill); //adapter.Upd dataGridViewPlayerSkill.DataSource = dataSetPlayerSkill.Tables[0]; adapter.Update(dataSetPlayerSkill); // Основная таблица tableNameMain = comboBox1.Text + " - " + comboBox2.Text; commandMain = new OleDbCommand("SELECT * FROM [" + tableNameMain + "];", connection); adapter.SelectCommand = commandMain; dataSetMain = new DataSet(); adapter.Fill(dataSetMain); dataGridViewMainBase.DataSource = dataSetMain.Tables[0]; adapter.Update(dataSetMain); connection.Close(); 
  • one
    You described only SELECT, to save, describe the UPDATE method in the desired cells. adapter.UpdateCommand = new OleDbCommand ("smart command for replacing a line with indication of a cell and internals of a new line", connetion); - xSx
  • @xSx added this row (updated the topic), the compiler no longer generates errors. Changes are saved if the cell is changed manually (double click on the cell and input the value), but if the cell is changed by the program (dataGridView2.Rows [0] .Cells [j] .Value = 2), then the database does not save changes - StriBog
  • one
    If you need to change the program values, why do it in the DataGridView? Make changes to the rows in the table in dataset and do not forget to call the AcceptChanges method to confirm the changes. After that, you can call the Update method. The problem in this case is that when double-clicking a change occurs dataset, and only then update the text of the table. You only change the text, but the data in the dataset does not change and the Update command has nothing to send to the database. - Pleshkov Ivan
  • @xSx appeared another problem, only the first request of all is updated, showed the example above, fill in the values ​​of line 1 in the first request, in line 2 with the second request - StriBog
  • Possible or AcceptChanges (); call or Validate (); I'll see later. So, when you change programmatically, it was possible to update immediately in the bazka and reload the label, as an option. - xSx

0