Visual Basic .NET Forums  
Click here to advertise with us

Go Back   Visual Basic .NET Forums > Database > ADO.NET

ADO.NET Anything regarding DataAdapters, DataReaders, DataSets, etc.

VB.NET Forums Newsletter Signup:
Email address:


Reply
 
LinkBack Thread Tools Display Modes
  #1 (permalink)  
Old 01-29-2010, 1:41 PM
VB.NET Forum Enthusiast
.NET Framework: .NET 3.0 (VS 2005/2008)
 
Join Date: Jan 2009
Posts: 35
Reputation: 17
cwfontan is on a distinguished programming path ahead
Default tranaction rollback vb.net question

can I loop the 2nd command and still rollback if everything is not complete?


Code:
     
        Try
            sqlconn.Open()
            'BeginTransaction() Requires Open Connection
            trans = sqlconn.BeginTransaction()

            'Assign Transaction to Command
            cmd.Transaction = trans

            '1st command to execute. This will be rollback if 2nd command fails
            cmd.CommandText = "UPDATE dbo.Security_GroupUsers SET Inactive=0 WHERE depotID=" & depotID & " AND GroupID=" & groupID
            cmd.ExecuteNonQuery()
            For Each user In lb_groupUsers_SecurityMgr.Items
                '2nd command to execute
                cmd.CommandText = "INSERT INTO dbo.Security_GroupUsers (groupID,depotID,userID,audit,Inactive) VALUES (" & groupID & "," & depotID & "," & userID & ",'" & Audit & "',0)"
                cmd.ExecuteNonQuery()
            Next
            trans.Commit()
        Catch
            trans.Rollback()
            Console.WriteLine("Error while processing command. Previous execution was rollback")
        Finally
            sqlconn.Close()
        End Try
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #2 (permalink)  
Old 01-29-2010, 1:57 PM
VB.NET Forum Genius
.NET Framework: .NET 2.0 (VS 2005)
 
Join Date: Mar 2008
Location: Minnesota
Posts: 214
Reputation: 210
demausdauth puts e.f. hutton to shamedemausdauth puts e.f. hutton to shamedemausdauth puts e.f. hutton to shamedemausdauth puts e.f. hutton to shamedemausdauth puts e.f. hutton to shamedemausdauth puts e.f. hutton to shamedemausdauth puts e.f. hutton to shamedemausdauth puts e.f. hutton to shame
Default

All the operations you perform with the command object that is in transaction should rollback or commit based on which one you call.
__________________
If someone has helped you please rate them.
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #3 (permalink)  
Old 02-02-2010, 6:24 AM
cjard's Avatar
VB.NET Forum All-Mighty
.NET Framework: .NET 2.0 (VS 2005)
 
Join Date: Apr 2006
Age: 65
Posts: 6,442
Reputation: 807
cjard has a reputation beyond reputecjard has a reputation beyond reputecjard has a reputation beyond reputecjard has a reputation beyond reputecjard has a reputation beyond reputecjard has a reputation beyond reputecjard has a reputation beyond reputecjard has a reputation beyond reputecjard has a reputation beyond reputecjard has a reputation beyond reputecjard has a reputation beyond repute
Default

please read the PQ link in my signature
__________________
DW1 DW2 DW3 DW4 DNU PQ
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
Reply

Bookmarks


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On





All times are GMT -4. The time now is 4:40 PM.

Powered by vBulletin® Version 3.8.5
Copyright ©2000 - 2010, Jelsoft Enterprises Ltd.
Search Engine Optimization by vBSEO 3.3.2


For advertising opportunities click here.