DataRow.AcceptChanges()

O

Osvaldo Bisignano

Hi guys n girls.

I get this error when updating my datatable:

foreach(DataRow dr in myTable.Rows)
{
try
{
MyCustomUpdater.Update(dr); //not a DataAdapter, a custom object.
//If no exception has been thrown
dr.AcceptChanges();
}
catch (Exception ex)
{
throw ex;
}
}

If the row has been deleted, when I call AcceptChanges the row is removed from the datatable, and after that the collection is modified, and foreach throws an error saying that the Collection has been modified and the Enumerator is not valid any more.

I need to accept changes inmediatly after each row has been succesfully updated to the database.
How can i avoid this situation?
How does the SQlDataAdapter.Update method resolves this?

Thanks
 
G

Greg

After you call Update, AcceptChanges is called for you by default. You do not need to manually call this again.
Hi guys n girls.

I get this error when updating my datatable:

foreach(DataRow dr in myTable.Rows)
{
try
{
MyCustomUpdater.Update(dr); //not a DataAdapter, a custom object.
//If no exception has been thrown
dr.AcceptChanges();
}
catch (Exception ex)
{
throw ex;
}
}

If the row has been deleted, when I call AcceptChanges the row is removed from the datatable, and after that the collection is modified, and foreach throws an error saying that the Collection has been modified and the Enumerator is not valid any more.

I need to accept changes inmediatly after each row has been succesfully updated to the database.
How can i avoid this situation?
How does the SQlDataAdapter.Update method resolves this?

Thanks
 
O

Osvaldo Bisignano

i'm not working with the DataAdapter Object from ADO.NET
I'm using a personalized class made by me to reproduce that work. So, when I acceptchanges for one row that has been deleted, the collection raises an error I cannot handle.

Does DataAdapter call AcceptChanges on the Table or row by row?
What happens if JUST one row has error? (Suppose I'm using ContinueUpdateOnError). Which will be the RowState of rest of the successfully updated rows? Does one row with errors cancel all the update?

Thanos Wins



"Greg" <[email protected]> escribió en el mensaje After you call Update, AcceptChanges is called for you by default. You do not need to manually call this again.
Hi guys n girls.

I get this error when updating my datatable:

foreach(DataRow dr in myTable.Rows)
{
try
{
MyCustomUpdater.Update(dr); //not a DataAdapter, a custom object.
//If no exception has been thrown
dr.AcceptChanges();
}
catch (Exception ex)
{
throw ex;
}
}

If the row has been deleted, when I call AcceptChanges the row is removed from the datatable, and after that the collection is modified, and foreach throws an error saying that the Collection has been modified and the Enumerator is not valid any more.

I need to accept changes inmediatly after each row has been succesfully updated to the database.
How can i avoid this situation?
How does the SQlDataAdapter.Update method resolves this?

Thanks
 
G

Greg

row by row
i'm not working with the DataAdapter Object from ADO.NET
I'm using a personalized class made by me to reproduce that work. So, when I acceptchanges for one row that has been deleted, the collection raises an error I cannot handle.

Does DataAdapter call AcceptChanges on the Table or row by row?
What happens if JUST one row has error? (Suppose I'm using ContinueUpdateOnError). Which will be the RowState of rest of the successfully updated rows? Does one row with errors cancel all the update?

Thanos Wins



"Greg" <[email protected]> escribió en el mensaje After you call Update, AcceptChanges is called for you by default. You do not need to manually call this again.
Hi guys n girls.

I get this error when updating my datatable:

foreach(DataRow dr in myTable.Rows)
{
try
{
MyCustomUpdater.Update(dr); //not a DataAdapter, a custom object.
//If no exception has been thrown
dr.AcceptChanges();
}
catch (Exception ex)
{
throw ex;
}
}

If the row has been deleted, when I call AcceptChanges the row is removed from the datatable, and after that the collection is modified, and foreach throws an error saying that the Collection has been modified and the Enumerator is not valid any more.

I need to accept changes inmediatly after each row has been succesfully updated to the database.
How can i avoid this situation?
How does the SQlDataAdapter.Update method resolves this?

Thanks
 

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