vb中删除SQL数据库中记录出现实时错误3021

来源:百度知道 编辑:UC知道 时间:2024/05/15 09:03:29
Private Sub Command2_Click()
Dim myval As String
myval = MsgBox("是否要删除记录?", vbYesNo)
If myval = vbYes Then
Adodc1.Recordset.Delete
Adodc1.Recordset.MoveNext
If Adodc1.Recordset.EOF = True Then Adodc1.Recordset.MoveLast
End Sub
错误提示:BOF或EOF中有一个是真,或者当前的记录被删除,所需的操作是要求当前的一个记录,
if 语句后有End if语句.
提示错误后结束程序,在看数据库中的记录已被删除,
按照楼上的修改之后又提示缺少更新或刷新的键列信息

因为你的数据记录指针没有指向你要删除的记录上,或者数据表是空的.在删除前先判断EOF或BOF状态吧

Private Sub Command2_Click()
Dim myval As String
myval = MsgBox("是否要删除记录?", vbYesNo)
If myval = vbYes Then Adodc1.Recordset.Delete
If Adodc1.Recordset.EOF = True Then Adodc1.Recordset.MoveLast
else Adodc1.Recordset.MoveNext
End Sub