上次有个贴问了事务的问题,如下
http://www.foxtable.com/bbs/dispbbs.asp?BoardID=2&ID=43350&skin=0
狐爸说可以编程解决,可惜我太菜了,搞不了,狐爸能不能搞个通用的解决示例 ,这个必须有啊,否则没有办法做下去了,
bin说用SQLCOMMAND也不能解决事物的问题,请指教!
这是我用ADO做的一个函数,是不是有参考意义
Public Function Trans(Optional ByVal strSQL1 As String, Optional ByVal strSQL2 As String, Optional ByVal strSQL3 As String, Optional ByVal strSQL4 As String, Optional ByVal strSQL5 As String, Optional ByVal strSQL6 As String, Optional ByVal strSQL7 As String, Optional ByVal strSQL8 As String, Optional ByVal strSQL9 As String, Optional ByVal strSQL10 As String) As Boolean
On Error GoTo Err_Trans
Dim CN As ADODB.Connection
Set CN = CurrentProject.Connection
Trans = True
CN.BeginTrans
If Nz(strSQL1, "") <> "" Then CN.Execute strSQL1
If Nz(strSQL2, "") <> "" Then CN.Execute strSQL2
If Nz(strSQL3, "") <> "" Then CN.Execute strSQL3
If Nz(strSQL4, "") <> "" Then CN.Execute strSQL4
If Nz(strSQL5, "") <> "" Then CN.Execute strSQL5
If Nz(strSQL6, "") <> "" Then CN.Execute strSQL6
If Nz(strSQL7, "") <> "" Then CN.Execute strSQL7
If Nz(strSQL8, "") <> "" Then CN.Execute strSQL8
If Nz(strSQL9, "") <> "" Then CN.Execute strSQL9
If Nz(strSQL10, "") <> "" Then CN.Execute strSQL10
CN.CommitTrans
CN.Close
Exit Function
Err_Trans:
CN.RollbackTrans
Trans = False
MsgBox Err.Description & " [操作失败,请检查!]", 0 + 64
CN.Close
End Function