2
Answers

How to Handle Single Transaction,Commit, RollBack

How to Handle Single Transaction,Commit, RollBack For multiple connections in ADO.net.
 
Actually I have Multi level  Hierarchal Models like:
 
Class1{ 
List
Class2{
List
List
Class5 
}
Class3{
List 
}
Class4{
}
Class5{
}
Class6{
 
There are six different Data Tables in DataBase for each and every class. For that  i written 6 different Stored procedures. Now i am trying to insert data , While inserting if Exception is occuring in Any one of the Child table, then transaction should RollBack the Resut. I am not getting How to do this. Please help me in this.
Answers (2)
0
Satyaprakash Samantaray

Satyaprakash Samantaray

NA 9.7k 1.1m 7y
https://www.codeproject.com/Articles/10223/Using-Transactions-in-ADO-NET
0
Tapan Patel

Tapan Patel

NA 8.1k 100.8k 7y
You need to surround your code with try catch block for each of the database operations in your methods and in order to rollback you can always use sqltransaction.begintransaction and sqltransaction.rollback methods.
 
Take a look at detailed example below:
http://www.c-sharpcorner.com/UploadFile/rohatash/performing-sql-server-transaction-using-ado-net/