Click here to Skip to main content
15,064,665 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
Please help me....
How can i program execute multiple query in single command with rollback when a foreign key present with two table and the second query fails rollback full of the queries..
Plz help me to do this in vb.net.

[Edit]
Removed blank SQL code block. Suresh
[/Edit]
Posted
Updated 25-Aug-11 20:49pm
v3
Comments
Suresh Suthar 26-Aug-11 2:49am
   
Can you please elaborate.

You need to use a Transactionscope[^]

VB
try
 using Trans as new transactionScope()
  'Do database work here

  Trans.commit()
 end using
catch ex as TransactionAbortedException
 messagebox.show ex.message
end catch


queries are not commited to the database until the commit is called. If an error is trapped then the queries are rolled back.

Simon
   
string query="query1;query2;query3";
open connection
sqlcommand cmd=new sqlcommand("query",connection,sqltransactionobject);
begin transaction

executenonquery()
if(fails)
rollback
otherwise
commit
close connection
   

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