Click here to Skip to main content
15,881,172 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
In my application I had a form where i have to do more than one database transaction within a single button click
ie
When I click button

Query 1 >>>insert designation values to Designation table

query 2. >>select query to get the primary key of last entered designation.... ie .the auto number against which the above insert query inserts

query 3 >> inset data into another table with the primary key recvd from above

query 4 .>> update another table with the primary Key Above

If any of the query fails or any exception occur The others shouldnot work


now I am trying to do it using try catch and deleting prevoius insertions if exception occurs...

Is there any good Ideas as I am new to sql server 2008
Posted

You can use TransactionScoe.

check this article and google for some more:

http://simpleverse.wordpress.com/2008/08/05/using-transactionscope-for-handling-transactions/[^]


Cheers
 
Share this answer
 
Hi,
Use Sql Stored Procedure[^] to perform all your database operation at a time. In that you need to use Sql Transaction[^] to rollback the transaction if any error occurs.
Refer the links:
Overview of SQL Server Stored Procedure[^]
SQL Server Transactions and Error Handling[^]


All the best.
--Amit
 
Share this answer
 
 
Share this answer
 
Hey there,

If you want to do it in the application level, use TransactionScope[^]. Otherwise, you can create a stored procedure to perform these tasks which will return a value based on the success of the requested tasks. You can use BEGIN TRANSACTION[^] within the SP for managing transactions.

For an example in SQL transactions click here[^]

Hope this helps, regards
 
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