This question has already been answered:

There is a function that removes the user-selected row from the database table, as well as all the rows from the child table that contain the same ID of the parent table. But after restarting the program, the changes are not saved, what could be the problem?

private void buttonDelete_Click(object sender, EventArgs e) { int numRow = bindingSourse.Position; string parentID = null; DataRow selectRow = dataSetDP_DB.Tables[DataSpr.NameTable].Rows[numRow]; foreach (DataColumn prCol in dataSetDP_DB.Tables[DataSpr.NameTable].Columns) { if (prCol.Unique == true) { int numCol = prCol.Ordinal; parentID = selectRow[prCol.Ordinal].ToString(); break; } } DataRow[] delrow = null; foreach (DataRelation relation in dataSetDP_DB.Tables[DataSpr.NameTable].ChildRelations) { int k = 0; foreach (DataColumn chCol in relation.ChildColumns) { foreach (DataRow row in relation.ChildTable.Rows) { if (row[chCol.Ordinal].Equals(parentID)) { row.Delete(); } } } } dataSetDP_DB.Tables[DataSpr.NameTable].Rows.RemoveAt(numRow); tableAdapterManagerSPR.UpdateAll(dataSetDP_DB); } 

Reported as a duplicate by PashaPash member c # Jan 16 '17 at 7:55 .

A similar question was asked earlier and an answer has already been received. If the answers provided are not exhaustive, please ask a new question .

  • No commit (commit changes). Either call it explicitly, or set autocommit in the properties of the object responsible for connecting to the database. - hinotf
  • But I do not have direct sql queries. If I understand correctly, are queries necessary to work with transactions? - Nade
  • I meant that you need to somehow call the method responsible for commit in ado.net. I do not know this framework, but in the above code there are no signs of commit. If when you close the application and re-open the line again in place, then a rollback implicitly occurred when closing the connection. - hinotf
  • Thank you very much for your explanations. But the fact is that the string "tableAdapterManagerSPR.UpdateAll (dataSetDP_DB)" should make all changes to the base. But for some reason this does not happen, this is where my original question follows - Nade
  • If you run your application not from the studio, but from the bin folder, after deleting and opening the program again, the deleted data still remains? - MaximK

1 answer 1

If you use a local database, there is one caveat: you need to change the Copy to output directory property in the database settings to Copy if newer (or try other options).