DataSet Transactions Rollback [HELP PLEASE]

B

Brian Scott

I have created a transaction and attached it to the dataadapter of my
dataset in question. When an exception is raised before the transaction is
commited the transaction is rolled back.

The problem I am having is that although the transaction rollback has
stopped the new datarow from being inserted into the underlying database, it
is still being added to the dataset object. I am using DataAdapter.Update on
my Datatable within the Dataset and then running an SqlCommand after this to
communicate with the database directly. If there is an exception when I rund
the SQLCommand which is after the DataAdapter.Update the information is
stopped from enterring the database but still added to the dataset even
though the transaction failed.

I have tried catching the exception raised by the SqlCommand use and calling
DataTable.RejectChanges but the changes have been accepted after the
succesfull DataAdapter.Update.

Am i doing something wrong here?
 
B

Brian Scott

I've worked out there area my problem arises.

When I call the DataAdapter.Update it sets my rows to be unchanged. But
within the transaction I may incur an error and need to rollback. How can I
possibly rollback my dataset when the rows are now marked as unchanged yet
the data is not in the underlying database due to the rollback?
 
M

Marina

There is a GetChanges method on the dataset. Pass that in to Update. If
everything is OK after the update, call AcceptChanges on the original
dataset. Otherwise, do nothing, and you still have your original dataset
intact.
 

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