请教各位大神!数据库有数据,代码没写错,为什么会Adodc1.Recordset.RecordCount=0 ?
问题描述
用vb6.0写用户管理窗体,
“注册用户”运行正常,注册了一个名叫"lucy
"的用户,然后点击“删除现有用户”进行测试“删除”的运行情况。
可为什么Adodc1.Recordset.RecordCount=0呢?
提示"当前数据库没有可删除的用户信息"。
查看SQL的数据表却可以看到lucy的数据,为什么无法删除lucy用户呢?
详细代码如下:
'删除现有用户的确定事件
Private Sub CmdSure2_Click()
rtn = SetWindowPos(Me.hwnd, -2, 0, 0, 0, 0, 3) '取消置前
'禁止删除当前用户
If Combo1.Text = Name1 Then
MsgBox "不能删除当前用户", vbInformation, "系统提示"
Else
a = MsgBox("您确定要删除该用户吗?", vbCritical + vbOKCancel, "系统提示")
If a = vbOK Then
'查询数据库,并将结果放进Adodc1.RecordSource中
Adodc1.RecordSource = "select * from tb_enter where vchUserName = ' " & Combo1.Text & " ' "
Adodc1.Refresh '刷新
'语法没问题,但是不会执行到这一步,无法删除用户信息
MsgBox Adodc1.Recordset.RecordCount '查看记录集的记录条数
If Adodc1.Recordset.RecordCount > 0 Then
Adodc1.Recordset.Delete '删除记录集中的数据
Adodc1.Refresh
MsgBox "用户信息删除成功", vbExclamation, "系统提示"
Unload Me
Else
MsgBox "当前数据库没有可删除的用户信息"
End If
End If
End If
End Sub
还望各位大神不吝赐教呀!