VB程序员博客

VB程序开发

用VB连接SQL serer 2005(数据库连接没有任何问题用的是ADODC控件)下面请大家帮忙看看错在哪里?
Private Sub Command1_Click()
Dim username, password As String
Dim rememberuser, rememberpassword As Integer
If Form1.Text1.Text = "" Then
MsgBox ("请输入用户名"), vbCritical, "提示"
ElseIf Form1.Text1.Text <> "" Then
Adodc1.RecordSource = "select * from userdetail where user =  '" & Form1.Text1.Text & "'"
Adodc1.Refresh
passsword = Adodc1.Recordset.Fields("password")
If password = Form1.Text2.Text Then
Form2.Show
End If

End If
End Sub
数据库中的表有2项分别是 user 和password 都是char(10)类型的
运行总是说关键字‘select’附近语法错误

首先说下:
Dim username, password As String
Dim rememberuser, rememberpassword As Integer
只定义了最后的password是string类型,和remenberpassword是integer类型,前面的两个是无类型的,
楼主去看看MSDN就知道了

其次:
"select * from userdetail where user =  '" & Form1.Text1.Text & "'"

改成:
"select * from userdetail where user = '" & Form1.Text1.Text & "' and '" & Form1.Text2.Text & "'"
然后只要判断recordcount是否大于0就知道是否匹配了.

还有,你说user 和password 都是char(10),那就规定了你的用户名和密码也必须是10位, 这样做不是很常见(不是不可以)
建议你使用VCHAR或NVCHAR类型

恩,谢谢wallescai指出的不足之处,问下"select * from userdetail where user = '" & Form1.Text1.Text & "' and '" & Form1.Text2.Text & "'"
然后只要判断recordcount是否大于0就知道是否匹配了.  具体该如何写,谢谢

form1.text2.text 是输入密码的地方  form1.text.text是输入用户名的
数据库的表名 userdetail  两项是user 和 password

Adodc1.RecordSource = " select * from userdetail where [user] =  '" & Form1.Text1.Text & "'"
Adodc1.Refresh
passsword = Adodc1.Recordset.Fields("[password]")

为什么现在又说实时错误3021
BOF 或 EOF 中有一个是真,或者当前的记录已被删除,所需的操作要求一个当前记录
user            password
123      123     
admin    123     
这是数据

自己顶下

谁能帮忙看看吗