Updating a Dataset 2nd part: Accepted/Rejected rows ?

G

Guest

Hello,

This is the second part of my question. Forgive me if this post is too long
but I like to formulate a complete question.

I am currently building the DALC for our company application. When updating
a Dataset I thought it could be interesting to keep track of the rows that
were succesfully updated to the data source. I CAN achieve this, but it does
not look the slickest solution when working with MULTIPLE 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!

(BTW, question on the side: Why do some examples appeal to calling
DataSet.AcceptChanges() after an Update .... isn't this done automatically by
the DataAdapter?)

Now, my problem with this solution is that my DAL is not using the
DataSet.GetChanges() method before calling DataAdapter.Update.

I know in
 
G

Guest

(sorry, pressed the wrong botton before finishing)

Hello,

This is the second part of my question. Forgive me if this post is too long
but I like to formulate a complete question.

I am currently building the DALC for our company application. When updating
a Dataset I thought it could be interesting to keep track of the rows that
were succesfully updated to the data source. I CAN achieve this, but it does
not look the slickest solution when working with MULTIPLE 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!

(BTW, question on the side: Why do some examples appeal to calling
DataSet.AcceptChanges() after an Update .... isn't this done automatically
by
the DataAdapter?)

Now, my problem with this solution is that my DAL is not using the
DataSet.GetChanges() method before calling DataAdapter.Update.

I know in a multiple tables datasets with relationships among the tables,
DataSet.GetChanges() 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 a pain, and the only soultion I see to this would be looping
right after each Merge, yet worse, Updating Modified and Added rows
separately!!!

Thanks in advance ... even for just reading up to this point
:)
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top