Run all
Protected Void Button2_click ( Object Sender, eventargs e ){ // Execute transactions Sqlconnection con = New Sqlconnection (STR); con. open (); sqltransaction tran = Con. begintransaction (); Try {Sqlcommand cmd1 = New Sqlcommand ( " Insert into code (name) values ('ww1 ') " , Con); sqlcommand cmd2 = New Sqlcommand ( " Insert into code (name) values ('ww2 ') " , Con); transaction 1.transaction =Tran; pai2.transaction = Tran; statement 1.executenonquery (); statement 2.executenonquery (); Tran. Commit ();} Catch {Tran. rollback ();} Finally {Con. Close (); getdata ();}}
Execute a transaction with a save point
Protected Void Button3_click ( Object Sender, eventargs e ){ // Execute a transaction with a save point // Execute transactions Sqlconnection con = New Sqlconnection (STR); con. open (); sqltransaction tran = Null ; Tran = Con. begintransaction (); Try {Sqlcommand cmd1 = New Sqlcommand (" Insert into code (name) values ('ww3 ') " , Con); sqlcommand cmd2 = New Sqlcommand ( " Insert into code (name) values ('ww4 ') " , Con); transaction 1.transaction = Tran; statement 1.executenonquery (); Tran. Save ( " One " ); Implements 2.transaction = Tran; export 2.executenonquery (); Tran. rollback ( " One " ); Tran. Commit ();} Catch {Tran. rollback ();} Finally {Con. Close (); getdata ();}}