Click here to Skip to main content
16,018,805 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Please see the following code snippet. I want that if "AddPersonalRecord" fails due to any reason or "AddOfficialRecord" fails, the changes done to the database must be rolled back. I am using SQL Server 2005 express edition. The methods, AddPersonalRecord and AddOfficialRecord, contains Insert Statements to insert record in the table.

I want something like:

if (answer == "yes")
{
Begin Transaction();
AddPersonalRecord();
AddOfficialRecord();
}
Posted

1 solution

You do need to use a Transaction, yes: SqlTransaction class[^]

It's pretty easy in theory (but I have no idea how your software works, so it's up to you to implement) - the link contains an example.
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900