Rolling back an insert

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

VS2003, C#

Hi,

I am adding rows into a parent & child tbl. First the parent tbl, then the
child. I have a list box & datagrid bound to a dataset displaying
parent/child rows. Both row adds are nested in a transaction. Within the
transaction I add the row(s), update the data source & accept the changes to
the DS.

If an error occurs, I rollback the transaction & reject the changes to the DS.

However, if an error occurs, although the new row (in the parent tbl) is not
persisted to the DB, it shows up in the list box that is bound to the dataset
until I restart the app.

I tried refilling the dataset in the catch but that doesn't seem to work. I
thought either rejecting the changes or refilling the DS would fix this but
no go.

Why is this happening?

Thanks for any ideas

Ant
 
Are you using the Update() method on the DataSet? If so, you have two
choices:

1. Rebind with the original rowset
2. Clear the dataset completely and rebind from the database

Make sure you have completely rolled back or committed prior to grabbing.

One suggestion:
If adding records to a dropdown, do it on a separate form and raise an event
to clear out the data. NOTE: you have to clear the dropdown and then refill
when you leave things in an inconsistent state.

--
Gregory A. Beamer
MVP; MCP: +I, SE, SD, DBA
http://gregorybeamer.spaces.live.com

*************************************************
Think outside of the box!
*************************************************
 
Back
Top