3

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

The DataSet has 4 tables -- 1 parent (single row table), 3 child. with foriegn cascade delete/update constraints. My intention is to ask the user for a new primary key (complex) and then try to tell the DataAdapter or DataSet to mark all the rows (and subsequent new ones) in the 4 tables as DataRowState.Added; But DataRow.SetAdded() throws exception "Can only SetAdded on DataRowState.Unchanged rows"

Anyone has idea how to do it? Any other efficient methods to do a "Save As" is also welcomed. Many thanks.

EDIT: Just in case, DataRelations have already been set. Normal INSERT, UPDATE, DELETE and SELECT works perfectly.

Jake
  • 11,273
  • 21
  • 90
  • 147

1 Answers1

6

maybe this works

row.AcceptChanges(); // sets DataRowState.Unchanged
row.SetAdded();
k3b
  • 14,517
  • 7
  • 53
  • 85
  • finally able to mark this as answer. Don't know why everytime I tried, it reports an error. Thanks. – Jake Jan 09 '11 at 15:13