C # DataSet, DataAdapter - How to change row state for INSERT call?

I am trying to implement a Save As button to take data into a DataSet, which was DataAdapter.Filled () and INSERT into a database.

There are 4 tables in the DataSet - 1 parent (a table with one row), 3 children. with restrictions for uninstalling / updating foriegn cascade. My intention is to ask the user a new primary key (complex), and then try to tell the DataAdapter or DataSet to mark all rows (and subsequent new ones) in 4 tables as DataRowState.Added; But DataRow.SetAdded () throws an exception "Can only SetAdded on DataRowState.Unchanged rows"

Does anyone have an idea how to do this? Any other effective Save As methods are also welcome. Many thanks.

EDIT: Just in case, DataRelations are already installed. Regular INSERT, UPDATE, DELETE, and SELECT work fine.

+3
source share
1 answer

maybe it works

row.AcceptChanges(); // sets DataRowState.Unchanged
row.SetAdded();
+5
source

Source: https://habr.com/ru/post/1783170/


All Articles