Click here to Skip to main content
Rate this: bad
good
Please Sign up or sign in to vote.
See more: C#3.0
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 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 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  
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 3

  Permalink  

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

  Print Answers RSS
0 Sergey Alexandrovich Kryukov 668
1 OriginalGriff 396
2 Tadit Dash 345
3 sanket saxena 329
4 Peter Leow 203
0 Sergey Alexandrovich Kryukov 12,109
1 OriginalGriff 7,326
2 Peter Leow 5,013
3 Abhinav S 4,013
4 Maciej Los 3,575


Advertise | Privacy | Mobile
Web04 | 2.8.140421.2 | Last Updated 10 Sep 2012
Copyright © CodeProject, 1999-2014
All Rights Reserved. Terms of Use
Layout: fixed | fluid