'带事务回滚的sql语句执行
Sub test()
Dim cnn As New ADODB.Connection
Dim sqls As New Collection
sqls.Add "sql语句1"
sqls.Add "sql语句2"
'....
cnn.ConnectionString = "" '以实际情况填写
cnn.Open
cnn.BeginTrans '开始事务
On Error GoTo err
For i = 0 To sqls.Count - 1
cnn.Execute strs(i)
Next
cnn.CommitTrans '提交事务
cnn.Close
Exit Sub
err:
cnn.RollbackTrans '如果错误,回滚
If cnn.State = 1 Then cnn.Close
End Sub
Vb Ado实现带事务回滚的sql语句执行
最新推荐文章于 2023-04-20 11:14:32 发布