VB6.0 连接无法用于执行此操作。在此上下文中它可能已被关闭或无效
时间:2011-09-09
来源:互联网
Private Sub Command1_Click()
If User.Text = "" Then
MsgBox "请输入用户名。", vbOKOnly + vbExclamation, "系统提示"
User.SetFocus
Exit Sub
End If
Call OpenCNN '打开数据库
Set RS = Nothing
RS.Open "select * form User where 用户编号= '" & User.Text & "'And 密码 = '" & MiMa.Text & "',con,1,1"
If RS.EOF = True Then
MsgBox "请重新输入学号或密码!"
User.Text = ""
MiMa.Text = ""
User.SetFocus
Else
MsgBox "登录成功"
End If
RS.Close
Zhu.Show
Unload Me
End Sub
以上是写在 登陆 按键里的
下面是写在模块里的
Global con As New ADODB.Connection
Global RS As New ADODB.Recordset
Public Sub OpenCNN()
Set con = Nothing
con.ConnectionString = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" & App.Path & "\物流管理.mdB"
con.ConnectionTimeout = 20 '打开等待时间
con.CursorLocation = adUseClient '设置或返回游标服务的位置
con.Open
End Sub
Public Sub CloseCNN()
If con.State Then con.Close
Set con = Nothing
End Sub
运行的时候总是提示 连接无法用于执行此操作。在此上下文中它可能已被关闭或无效
错误代码在这句:RS.Open "select * form User where 用户编号= '" & User.Text & "'And 密码 = '" & MiMa.Text & "'"
哪们高手帮忙看一下,为了这个东西,我找了很多资料。谢谢!
作者: puhong923 发布时间: 2011-09-09
作者: xiaoyao961 发布时间: 2011-09-09
在一个“成员查询”界面上要输入一个人的姓名来查询数据库中的这个人的全部信息并显示在界面上[答疑]
作者: xiaoyao961 发布时间: 2011-09-09
作者: mmxx0212 发布时间: 2011-09-09
RS.Open "select * form User where 用户编号= '" & User.Text & "'And 密码 = '" & MiMa.Text & "',con,1,1"
要改成:
RS.Open "select * form User where 用户编号= '" & User.Text & "'And 密码 = '" & MiMa.Text & "'",con,1,1
不用模块或函数的方式,很容易搞错
要是用我那个函数:Function OpenAccess(Mdbfilepath As String, Optional Mdbpassword As String, Optional usemdw As Boolean) As Boolean
再取一下数据就肯定不会错。
VB code
'┏〓〓〓〓〓〓〓〓〓 GetRs,start 〓〓〓〓〓〓〓〓〓┓ Function GetRs(Sql, Optional ErrInfo As String) As ADODB.Recordset '[mycode_id:1843],edittime:2011-1-17 下午 08:34:21 On Error GoTo Err Dim Rs As New ADODB.Recordset 'Set Rs = CreateObject("adodb.recordset") Rs.open Sql, Conn, 1, 3 Set GetRs = Rs Exit Function Err: ErrInfo = Err.Description End Function '┗〓〓〓〓〓〓〓〓〓 GetRs,end 〓〓〓〓〓〓〓〓〓┛ SUB TEST() Dim Rs As New ADODB.Recordset SET RS=GETRS("select * form User where 用户编号= '" & User.Text & "'And 密码 = '" & MiMa.Text & "'") MSGBOX RS(0) END SUB
作者: xiaoyao961 发布时间: 2011-09-09
作者: Veron_04 发布时间: 2011-09-09
2,user是系统保留字,不建议作为表名与字段名使用,一定要用则需要用方括号括起来
3,最后一个双引号的位置应该在con的逗号之前
RS.Open "select * form [User] where 用户编号= '" & User.Text & "'And 密码 = '" & MiMa.Text & "'",con,1,1
作者: Leftie 发布时间: 2011-09-09
热门阅读
-
office 2019专业增强版最新2021版激活秘钥/序列号/激活码推荐 附激活工具
阅读:74
-
如何安装mysql8.0
阅读:31
-
Word快速设置标题样式步骤详解
阅读:28
-
20+道必知必会的Vue面试题(附答案解析)
阅读:37
-
HTML如何制作表单
阅读:22
-
百词斩可以改天数吗?当然可以,4个步骤轻松修改天数!
阅读:31
-
ET文件格式和XLS格式文件之间如何转化?
阅读:24
-
react和vue的区别及优缺点是什么
阅读:121
-
支付宝人脸识别如何关闭?
阅读:21
-
腾讯微云怎么修改照片或视频备份路径?
阅读:28