Click here to Skip to main content
16,019,764 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi All,

I have one to many relation in parent child table. I want to insert records is both table in single transaction. If because of any reason child table records not get inserted then parent record also need to rollback.

How would we achieve this in business layer using asp.net.

Thanx & Regards
Santosh
Posted

1 solution

The best way to do this is to create it as a stored procedure, but whether you do that or inline the code what you really need to do is create a Transaction, which you either Commit after both inserts have succeeded, or Rollback if either fails.

Exactly how you do that will depend on in-line or SP, and the language you choose, but for SP see here: http://technet.microsoft.com/en-us/library/ms188929.aspx[^] and for C# see here: http://msdn.microsoft.com/en-us/library/system.data.sqlclient.sqltransaction.aspx[^]
 
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