In the program, I assign the value directly to the dataset, trying to change the data in the database

for (int j=1; j< dataSetPlayerSkill.Tables[0].Rows[0].ItemArray.Count; j++) { dataSetPlayerSkill.Tables[0].Rows[0].ItemArray[j] = matrixAlternativ[0][j]; dataSetPlayerSkill.Tables[0].Rows[1].ItemArray[j] = matrixAlternativ[1][j]; dataSetPlayerSkill.Tables[0].Rows[2].ItemArray[j] = matrixAlternativ[2][j]; } 

After that I want to save these changes.

 connection.open(); dataSetPlayerSkill.AcceptChanges(); adapter.Update(dataSetPlayerSkill); connection.Close(); 

But they are not saved. My database consists of [Code] - counter (primary key), [Pole1] - text

If you remove the dataSetPlayerSkill.AcceptChanges(); then an error occurs

enter image description here

  • @Vadim Ovchinnikov, and what does this question identify as ado.net ? - 4per
  • @ 4per DataSet , DataAdapter . - Vadim Ovchinnikov
  • @VadimOvchinnikov so these are general classes, not for ado.net exactly - 4per

1 answer 1

Just remove the dataSetPlayerSkill.AcceptChanges(); This method changes the attribute of the modified lines, setting "unchanged" . The method is useful in other cases, but not when you want to save changes to the database.


The error that you demonstrate in updating the question indicates that the answer has helped you, and your adapter started to call a command that is stored in its UpdateCommand property. But he ran into a problem when calling this command. The command may not be set, or the command may be incorrect.

  • Removed, there was an error about UpdateCommand - StriBog
  • This is because, before this, the adapter.UpdateCommand did not work. Understand what is wrong with him. What exactly from your example cannot be said unequivocally is a problem of a different kind than you originally identified in the question. You have received the answer to the question. - 4per