主题:请教一个关于数据库事务的运用的问题
写了一段向guests表中添加数据的代码,如下:
On Error GoTo Err
cnn.BeginTrans '事务开始
str = "insert into guests(roomcode,name,age,certificate,remarks) values('" & txtRoomCode.Text & "','" & txtName.Text & "','" & txtAge.Text & "'','" & txtCertificate.Text & "','" & txtRemarks.Text & "')"
Debug.Print str '调试
cnn.Execute str
MsgBox "登记成功", vbOKOnly + vbInformation, "提示"
cnn.CommitTrans '事务结束
Exit Sub '跳过Err,结束过程
Err:
cnn.RollbackTrans '事务回滚
MsgBox "登记失败", vbOKOnly + vbInformation, "提示"
自己没觉得哪儿出错了,但总是返回“登记失败”,想请帮忙解答一下:-)
On Error GoTo Err
cnn.BeginTrans '事务开始
str = "insert into guests(roomcode,name,age,certificate,remarks) values('" & txtRoomCode.Text & "','" & txtName.Text & "','" & txtAge.Text & "'','" & txtCertificate.Text & "','" & txtRemarks.Text & "')"
Debug.Print str '调试
cnn.Execute str
MsgBox "登记成功", vbOKOnly + vbInformation, "提示"
cnn.CommitTrans '事务结束
Exit Sub '跳过Err,结束过程
Err:
cnn.RollbackTrans '事务回滚
MsgBox "登记失败", vbOKOnly + vbInformation, "提示"
自己没觉得哪儿出错了,但总是返回“登记失败”,想请帮忙解答一下:-)