[Okta Webinar] Learn how to a build a cloud-first strategyRegister Now

x
?
Solved

Begin Transaction SQL insert in VB Winforms

Posted on 2007-10-18
4
Medium Priority
?
1,209 Views
Last Modified: 2013-11-07
Hi,
I have a winforms application that inserts Items into my Database. I want to insert the items using the "Begin Transaction" SQL Statement and when it is finished with NO errors I want to commit the transaction to the database. If there were errors in the Transaction, I want to Roll back my Transaction.

Would this be good practice? If so, does anyone have some sample VB code that I can modify?

Thanks for the help.
0
Comment
Question by:ALawrence007
  • 2
4 Comments
 
LVL 4

Assisted Solution

by:jindalankush
jindalankush earned 800 total points
ID: 20101191
Public objCon As New ADODB.Connection
objCon.BeginTrans
    objCon.CommitTrans
    objCon.RollbackTrans
0
 
LVL 8

Accepted Solution

by:
matrix_aash earned 1200 total points
ID: 20101416
You can write a stored procedure and a transaction in the SP, and run that in your Windows application

For e.g you can create something along the lines:

BEGIN TRANSACTION
IF sql statement
else
IF (@@Error = 0) AND (@@ROWCOUNT <> 0)
      BEGIN
        COMMIT TRANSACTION
    END
          ELSE
    BEGIN
            ROLLBACK TRANSACTION
    END

If you put the above in stored procedure and use that in your Windows application it should do what you want.

Please let me know if this helps


Aash.
0
 

Author Comment

by:ALawrence007
ID: 20101505
Aash,

This answer helped me in this situation.

jindalankush,

Helped me in other sections of my project.
0
 
LVL 4

Expert Comment

by:jindalankush
ID: 20107275
ya sure
you can mail to me ankjindal@yahoo.co.in
0

Featured Post

Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

This month, Experts Exchange sat down with resident SQL expert, Jim Horn, for an in-depth look into the makings of a successful career in SQL.
MSSQL DB-maintenance also needs implementation of multiple activities. However, unprecedented errors can hamper the database management. In that case, deploying Stellar SQL Database Toolkit ensures fast and accurate database and backup repair as wel…
Via a live example, show how to backup a database, simulate a failure backup the tail of the database transaction log and perform the restore.
This tutorial covers a step-by-step guide to install VisualVM launcher in eclipse.
Suggested Courses

873 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question