Click here to Skip to main content
12,250,327 members (51,699 online)
Rate this:
 
Please Sign up or sign in to vote.
See more: C#3.0 C#
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 10-Sep-12 1:47am
Rate this: bad
 
good
Please Sign up or sign in to vote.

Solution 1

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
  Permalink  
Rate this: bad
 
good
Please Sign up or sign in to vote.

Solution 2

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
  Permalink  
Rate this: bad
 
good
Please Sign up or sign in to vote.

Solution 3

  Permalink  
Rate this: bad
 
good
Please Sign up or sign in to vote.

Solution 4

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
  Permalink  

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

  Print Answers RSS
Top Experts
Last 24hrsThis month


Advertise | Privacy | Mobile
Web02 | 2.8.160426.1 | Last Updated 10 Sep 2012
Copyright © CodeProject, 1999-2016
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100