![]() |
Click here to advertise with us
|
|
|||||||
| ADO.NET Anything regarding DataAdapters, DataReaders, DataSets, etc. |
![]() |
|
|
LinkBack | Thread Tools | Display Modes |
|
|||
|
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
|
|
|||
|
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.
|
![]() |
| Bookmarks |
| Currently Active Users Viewing This Thread: 1 (0 members and 1 guests) | |
| Thread Tools | |
| Display Modes | |
|
|