Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

saving and then undoing the changes of an insert statment

Status
Not open for further replies.

steve1rm

Programmer
Aug 26, 2006
255
GB
Hello

VS 2005

I am using typed dataset in my vb project.

In my window the user will insert a new customer

TA_Customer.insert(,,,,,,,)

but if they change their mind and decide they don't want to insert a new one. Is it possible to roll back the changes.

The customer wants be able to add a new customer, then if they change their mind, click close on the window and not commit the changes.

Many thanks for any ideas or code,

Steve
 
Classic screwed up business process. Not your fault though obviously.

It will really depend on how you are handling the transactions in your ASP.NET front end. If you are giving them the ability to view the records (like a gridview) then you can just have them do something like a select row in the grid and delete it from there pretty easily. If you are not doing something like that then you're going to have to store the last identity inserted giving a stable pointer back to the row in the database. It would be extremely bad for you to not store the identity in your application and reply on getting the last inserted or max() identity due to multiple inserts coming from other places. Setting a property to the last identity would be a way. You can then use that as your value to roll back based on the users events.

I cannot think of a way in SQL for you to roll back the transaction successfully without having problems from other transactions if the original INSERT was already committed so the front end is your bet place to handle it

[sub]____________ signature below ______________
The worst mistake you'll ever make is to do something simply the way you know how while ignoring the way it should be done[/sub]
 
Another way would be to store the inserts in your application all together and have them do one main insert into the database. More or less store the transactions in memory and only when they are done processing then allwo the transaction to occur. You could do that with a dataset or datatable very easily also

[sub]____________ signature below ______________
The worst mistake you'll ever make is to do something simply the way you know how while ignoring the way it should be done[/sub]
 
I was thinking of doing something like holding the data in the memory of the typed dataset then clearing this if the user decides close the form.

Thanks for any more help,

Steve
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top