Multiple Update

  • Thread starter =?iso-8859-1?Q?Jos=E9_Tavares?=
  • Start date
?

=?iso-8859-1?Q?Jos=E9_Tavares?=

I've got a pieace of code that calls
IDbDataAdaptar::Update several times inside a transaction.
Pseudo Code:

TRY
Begin Transaction
update(a table) //AcceptChanges was run
update(some other table) // AcceptChanges was run
update(another table) // Fails
Commit
CATCH
RollBack

When the last call to update fails, the update method made
AcceptChanges to the first two datatables. So the physical
trasaction was rolled back but the logical transaction was
commited for two of the tables :( , inconsystency.
There's any method to disable the (auto)AcceptChanges from
the DataSet/Datatable.

Thanks in advance,
José Tavares
 
D

David Sceppa

José,

The simplest option is to store the contents of your DataSet
just prior to submitting changes. Then, if you decide to roll
back the transaction, you revert back to the DataSet in its prior
state. You could write the data out as a diffgram to a file or a
stream of memory using DataSet.WriteXml. You could also just
maintain a copy of the DataSet in memory by using DataSet.Copy.

I believe you could trap for the DataAdapter's RowUpdated
event and set RowUpdatedEventArgs.Status to
UpdateStatus.SkipCurrentRow to prevent the implicit call to
DataRow.AcceptChanges. The drawback is that if you decide to
commit the transaction but you were only submitting a subset of
the pending changes in your DataSet or DataTable, you'd need to
keep track of which rows on which to later explicitly
AcceptChanges.

I hope this information proves helpful.

David Sceppa
Microsoft
This posting is provided "AS IS" with no warranties,
and confers no rights. You assume all risk for your use.
© 2003 Microsoft Corporation. All rights reserved.
 

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