请教ACCESS数据库事务处理问题:事务处理过程中,连接对对象不能被明确地切断
我想在VB程序中用事务对ACCESS数据库多个表进行操作
Public Sub BeginTransX(TmpUser As String, TmpEmail As String)
Dim cnn As ADODB.Connection
Dim rst As ADODB.Recordset
'关键New用于创建新对象cnn
Set cnn = New ADODB.Connection
cnn.ConnectionString = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source= " _
+ App.Path + "\ " + DATABASE + ";Jet OLEDB:Database Password=123 " '设置连接字符串ConnectionString属性
'打开到数据库的连接
cnn.Open
'判断连接的状态
If cnn.State <> adStateOpen Then
'如果连接不成功,则显示提示信息,退出程序
MsgBox "数据库连接失败 "
End
End If
'创建Command对象cmd
' Dim cmd As New ADODB.Command
'设置cmd的ActiveConnection属性,指定与其关联的数据库连接
' Set cmd.ActiveConnection = cnn
'开始事务
cnn.BeginTrans
SqlStmt = "Update User_Info Set Email_PreTotal=0 " + " WHERE User_Id= ' " + Trim(TmpUser) + " ' and Email_Address= ' " + Trim(TmpEmail) + " ' "
'设置要执行的命令文本
'cmd.CommandText = SqlStmt
'执行命令
'cmd.Execute
cnn.Execute (SqlStmt)
SqlStmt = "DELETE * FROM Email_Records WHERE Email_Receiver= ' " + Trim(TmpEmail) + " ' "
'设置要执行的命令文本
'cmd.CommandText = SqlStmt
'执行命令
'cmd.Execute
cnn.Execute (SqlStmt)
SqlStmt = "Delete * FROM UIDL_List WHERE Email_Address= ' " + Trim(TmpEmail) + " ' "