数据库查询

zilingzhang 2002-04-29 11:51:25
我在全局变量中定义了
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
程序进入主界面后我定义了“重新登陆”功能,但为什么以上代码不能运行,错误显示为
“在一个已管理或无效连接上的对照参照引用不允许”
...全文
39 1 打赏 收藏 转发到动态 举报
AI 作业
写回复
用AI写文章
1 条回复
切换为时间正序
请发表友善的回复…
发表回复
tony_jian 2002-04-29
  • 打赏
  • 举报
回复
set rst=nothing

1,217

社区成员

发帖
与我相关
我的任务
社区描述
VB 数据库(包含打印,安装,报表)
社区管理员
  • 数据库(包含打印,安装,报表)社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧