Adodc控件与SQL数据库连接处理查询数据问题
以下是一个用户登录程序设计代码:
Const MaxLogTimes As Integer = 3
Private Sub cmdCancel_Click()
If MsgBox("你选择了退出系统登录,退出将不能启动管理系统!" & vbCrLf & "是否真的退出?", vbYesNo, "登录验证") = vbYes Then
End
End If
End Sub
Private Sub cmdOK_Click()
Dim strName As String, strPassword As String
'静态常量intLogTimes用于保存用户请求验证的次数
Static intLogTimes As Integer
intLogTimes = intLogTimes + 1 '保存登录次数
If intLogTimes > MaxLogTimes Then
'超过允许的登录次数,显示提示信息
MsgBox "你已经超过允许的登录验证次数!" & vbCr & "应用程序将结束!", vbCritical, "登录验证"
End '结束应用程序
Else
'进一步验证登录信息的合法性
strName = txtUserName.Text
strPassword = txtPassword.Text
'检验用户名和密码的合法性,并根据检验返回值执行相应的操作
Select Case Check_PassWord(strName, strPassword)
Case 0
'用户不是系统用户
MsgBox "用户不是系统用户,请检查用户名输入是否正确!", vbCritical, "登录验证"
txtUserName.SetFocus
txtUserName.SelStart = 0
txtUserName.SelLength = Len(txtUserName)
Case 1
'密码错误
MsgBox "密码错误,请重新输入!", vbCritical, "登录验证"
txtPassword = ""
txtPassword.SetFocus
Case 2
Unload Me '密码正确,卸载登录窗体
MsgBox "登录成功,将启动系统程序!", vbInformation, "登录验证"
FrmManPurchase.Enabled = True
Case Else
'登录验证未正常完成
MsgBox "登录验证未正常完成!请重新运行登录程序," & vbCrLf & "如果仍不能登录,请报告系统管理员!", vbCritical, "登录验证"
End Select
End If
End Sub
Private Function Check_PassWord(ByVal UserName As String, ByVal PassWord As String) As Byte
Adodc1.ConnectionString = "driver={SQL Server};server=MIJK;uid=;pwd=;database=ERP"
Adodc1.RecordSource = "select 密码 from user where 用户名='" & UserName & "'"
'判断有无查询结果
If Adodc1.Recordset.EOF Then
Check_PassWord = 0 '没有查询结果,表示该用户为非法用户
Else
'检查密码是否正确
If PassWord <> Trim(Adodc1.Recordset.Fields("密码").Value) Then
Check_PassWord = 1 '密码不正确
Else
Check_PassWord = 2 '密码正确
End If
End If
End Function
下面是报错的地方:
If Adodc1.Recordset.EOF Then 错误提示:对象变量或 With 块变量没有设置
请问这是怎么回事?
请各位帮忙解决问题!!