in Codex

Access事务执行多个sql语句

dim cn as string
   Dim cnConn As ADODB.Connection
   Set cnConn = New ADODB.Connection
    Dim mysql
    On Error GoTo err1

cn=""
'连接字符串自己写
   cnConn.Open CN
   cnConn.BeginTrans '开始一个事务
   
   For Each mysql In sql
        cnConn.Execute mysql
   Next
   cnConn.CommitTrans '提交一个事物
   
   Set cnConn = Nothing
   Exsql = True
   Exit Function
err1:
    cnConn.RollbackTrans '回滚一个事物
    Exsql = False
End Function

Write a Comment

Comment