DataRow.AcceptChanges()

  • Thread starter Thread starter Osvaldo Bisignano
  • Start date Start date
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
 
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
 
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
 
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
 
Back
Top