VB没有为命令对象设置命令

来源:百度知道 编辑:UC知道 时间:2024/05/22 20:08:32
Private Sub Command2_Click()
Dim db As New ADODB.Connection
Dim RsUser As New ADODB.Recordset
Dim strSql As String
Dim connStr As String

'2、打开数据库连接
connStr = "Driver={Microsoft Access Driver (*.mdb)}; DBQ=" & App.Path & "\custom.mdb" '连接Access的连接字符串
db.CursorLocation = adUseClient
db.Open connStr

str1 = "select * from 用户信息 where 用户名='" & Text1.Text & "' and 密码='" & Text2.Text & "' "
RsUser.Open strSql, db, adOpenDynamic, adLockReadOnly

If RsUser.EOF = True Then
Form7.Show
Exit Sub
Else
Form5.Show
End If

End Sub

错误在此处:
-----------------------------------------
str1 = "select * from 用户信息 where 用户名='" & Text1.Text & "' and 密码='" & Text2.Text & "' "
----------------------------------------
将上面的代码变为如下就可以了:
++++++++++++++++++++++++++++++++++++++++
strsql= "select * from 用户信息 where 用户名='" & Text1.Text & "' and 密码='" & Text2.Text & "' "
++++++++++++++++++++++++++++++++++++++++

建议你在以后的学习过程当中都在写代码之前加上:
Option Explicit
来检测你的代码中变量的声明

你真是太粗心了,变量写错了。错误在此处:
-----------------------------------------
str1 = "select * from 用户信息 where 用户名='" & Text1.Text & "' and 密码='" & Text2.Text & "' "
----------------------------------------
将上面的代码变为如下就可以了:
++++++++++++++++++++++++++++++++++++++++
strsql= "select * from 用户信息 where 用户名='" & Text1.Text & "' and 密码='"