数据库查询
我在全局变量中定义了
Public cnn As New ADODB.Connection
程序开始显示登陆窗口,检验用户是否存在
Dim rst As New ADODB.Recordset
Dim strSQL
Dim count As Integer
Dim userType As String
If txtUser.Text = "" Then
MsgBox "请输入用户名!", vbCritical, "警告!"
txtUser.SetFocus
ElseIf txtPassword.Text = "" Then
MsgBox "请输入该用户名密码!", vbCritical, "警告!"
txtUser.SetFocus
Else
cnn.ConnectionString = "DSN=tax_db;UID=dba;PWD=sql"
cnn.Open
strSQL = "select * from users where usr_id='" & txtUser.Text & "' and pwd ='" & txtPassword.Text & "'"
rst.Open strSQL, cnn, adOpenKeyset, adLockOptimistic
count = rst.RecordCount
If count > 0 Then
currUser = " 当前用户: " & txtUser.Text & " 权限类型: " & rst!usr_type
Login = rst!usr_type
Unload Me
MDIMain.Show
Else
MsgBox "用户名和密码不匹配!", vbCritical, "错误!"
rst.Close
cnn.Close
End If
End If
程序进入主界面后我定义了“重新登陆”功能,但为什么以上代码不能运行,错误显示为
“在一个已管理或无效连接上的对照参照引用不允许”