Why not it has all the information from the original dataset and it is only
The short answer: Because it is a copy, GetChanges generates a subset of the
rows in an entirely different DataSet. The DataRow.RowError information is
there, but in the copy, not in the original DataSet.
For the long answer I am copying this from my other post:
When updating a SINGEL TABLE Dataset I keep track of the rows that were
succesfully updated , but it does not look the slickest solution when working
with MULTIPLE RELATED TABLES.
Here is what I do (quite simple):
1. Registering my adapter to handle the RowUpdated event:
myDataAdapter.RowUpdated +=new
OleDbRowUpdatedEventHandler(myDataAdapter_RowUpdated);
2. Handling the RowUpdated event to store the error message and skip the
AcceptChanges call:
private static void myDataAdapter_RowUpdated(object sender,
OleDbRowUpdatedEventArgs e)
{
if (e.Status == UpdateStatus.ErrorsOccurred)
{
e.Row.RowError = e.Errors.Message;
e.Status = UpdateStatus.SkipCurrentRow;
}
}
3. And last, simply updating the data set:
myDataAdapter.Update(myDataSet);
Since "SkipCurrentRow" will skip the call to DataRow.AcceptChanges(), the
resulting dataset (after it has been updated) will keep the RowState for
those rows where an error ocurred, the rest of the rows will have a
"Unchanged" state. This is all great!!!
Now, in a multiple tables datasets with relationships among the tables, the
DataSet.GetChanges() method is a MUST to control the order in which updates
are
performed.
The question is:
--- How do I get the same behaviour of keeping track of the rows that were
sucessfully updated ? Since when using DataSet.GetChanges(), I am sending
copies of the DataSet to the DataAdapter.Update (instead of passign the
DataSet itself), then the RowState and RowError are not stored in my
original
DataSet. ---
My solution so far involves merging the copies of the DataSet with the
original DataSet. This works, but to a certain extend:
DataSet originalDS;
DataSet deletedDS = originalDS.GetChanges(DataRowState.Deleted);
DataSet modifiedDS = originalDS.GetChanges(DataRowState.Added
|DataRowState.Modified);
originalDS.AcceptChanges(); //reseting the row states
myDataAdapter2.Update(deletedDS, "Table2");
myDataAdapter1.Update(deletedDS, "Table1");
originalDS.Merge(deletedDS); //getting the Errors copied into the original DS
myDataAdapter1.Update(modifiedDS, "Table1");
myDataAdapter2.Update(modifiedDS, "Table2");
originalDS.Merge(modifiedDS); //getting the Errors copied into the original
DS
At this point my DataSet has the RowError messages, BUT the RowStates for
the Rows with Error are all set Modified, instead of Added, Deleted or
Modified (This is the effect of performing the DataSet.Merge.) Compared to
the single table DataSet, this solution is a pain, and the only way I see
around it would be looping right after each Merge, yet worse, updating
Modified and Added rows
separately!!!
Thanks for your opinions .... and for reading this far