Link to home
Create AccountLog in
Avatar of Murray Brown
Murray BrownFlag for United Kingdom of Great Britain and Northern Ireland

asked on

ASP.net C# Web Forms rolling back data insertion into two separate tables

Hi

In my ASP.net  C# web forms code below I am inserting SQL data into my "Sales Order" table using the code below and then gathering the ID of the newly inserted record and using it to insert multiple records in my "Sales Order Details" which contains a column called "Sales Order ID".

Is there a way to roll all of this back if there is an error at any point. In other words I want to cancel the data being inserted into both tables.

Avatar of slightwv (䄆 Netminder)
slightwv (䄆 Netminder)

What code?

But just like your previous question:
If everything is in a single transaction, you commit or rollback the entire transaction.
ASKER CERTIFIED SOLUTION
Avatar of slightwv (䄆 Netminder)
slightwv (䄆 Netminder)

Link to home
membership
Create an account to see this answer
Signing up is free. No credit card required.
Create Account

As I said in your previous question - the link there is still applicable - use a transaction with commit/rollback.

Everything done within the transaction is either put to the database or trashed with the commit/rollback, no matter how many records or tables are affected.

SOLUTION
Link to home
membership
Create an account to see this answer
Signing up is free. No credit card required.
Create Account
SOLUTION
Link to home
membership
Create an account to see this answer
Signing up is free. No credit card required.
Create Account