|
-
Sep 12th, 2001, 05:04 PM
#1
Thread Starter
Frenzied Member
BeginTrans - CommitTrans
I'm using an ADO 2.5 reference/VB6/Access2
I'm a little confused about the proper way to use the BeginTrans, CommitTrans, and RollBackTrans in my situation. In the ADO help file on the MSDN CD they show a situation where you open a record set, then loop through and make changes to some records, and then ask the user to CommitTrans.
In my situation I need to UPDATE records in one table and then DELET records in another table. Would I have one transaction with one set of BeginTrans-CommitTrans, or should I have Two sets of BeginTrans - CommitTrans, one nested inside the other.
VB Code:
'Option One
objConn.BeginTrans
sSQL = "UPDATE TableOne SET MyID = " & iNewID & " WHERE MyID = " & iOldID
objCmd.ActiveConnection = objConn
objCmd.CommandText = sSQL
objCmd.CommandType = adCmdText
objCmd.Execute lRows1
sSQL = "DELETE FROM TableTwo WHERE MyID = " & iOldID
objCmd.ActiveConnection = objConn
objCmd.CommandText = sSQL
objCmd.CommandType = adCmdText
objCmd.Execute lRows2
If MsgBox(lRows1 + lRows2 & " Will be changed or deleted.", vbYesNo, App.Title) = vbYes Then
objConn.CommitTrans
Else
objConn.RollbackTrans
End If
'Option Two
objConn.BeginTrans
sSQL = "UPDATE TableOne SET MyID = " & iNewID & " WHERE MyID = " & iOldID
objCmd.ActiveConnection = objConn
objCmd.CommandText = sSQL
objCmd.CommandType = adCmdText
objCmd.Execute lRows1
objConn.BeginTrans
sSQL = "DELETE FROM TableTwo WHERE MyID = " & iOldID
objCmd.ActiveConnection = objConn
objCmd.CommandText = sSQL
objCmd.CommandType = adCmdText
objCmd.Execute lRows2
If MsgBox(lRows1 + lRows2 & " Will be changed or deleted.", vbYesNo, App.Title) = vbYes Then
objConn.CommitTrans
objConn.CommitTrans
Else
objConn.RollbackTrans
objConn.RollbackTrans
End If
Greg
Free VB Add-In - The Reference Librarian
Click Here for screen shot and download link.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|