注册 登录
编程论坛 VB6论坛

求教一个查询输出问题

wxflw 发布于 2012-02-12 16:29, 485 次点击
窗体有一个adodc1控件,没有表格控件
Private Sub Command1_Click()
If Text1.Text = "" Then
    MsgBox "请您输入查询条件", 32, "房源管理系统"
     Exit Sub
Else
    = adCmdText
   Adodc1.RecordSource = "select * from user where username='" & (Text2.Text) & "'"
   Adodc1.Refresh  《《------这里出错了!form子语句法错误,对象Refresh的方法IADODC方法失败,这句删除可以往下运行但是下面出错
If Adodc1.Recordset.RecordCount > 0 Then   《《------上面删除,这里出错了。对象变量或with变量块未设置,实时错误‘91’
   Text2.Text = Adodc1.Recordset.Fields("username")
   Text3.Text = Adodc1.Recordset.Fields("userpwd")
   Combo1.Text = Adodc1.Recordset.Fields("userqx")
Else
    MsgBox "没有您要查找的员工,请您确认后重新输入", 32, "房源管理系统"
   End If
   End If
End Sub

我是想通过text1的值查找这个用户名把这个用户的 名字,密码,权限分别显示在texe2,text3,combo1中。
3 回复
#2
wxflw2012-02-12 20:11
找到原因了!但是不知道为什么,高手解释一下啊!学习学习!!

Adodc1.RecordSource = "select * from user where username='" & (Text2.Text) & "'"

改成
Adodc1.RecordSource = "select * from [user] where username='" & (Text2.Text) & "'"
那个USER为什么要加个[  ]才行啊?知道的指点下!迫切需要解释!!学习中!
#3
zhuyongxing2012-02-13 19:45
user库默认是系统库就像我们定义一样。有时候不能用dim Long as string
#4
yiyaozjk2012-02-14 20:04
学习了....
以下是引用zhuyongxing在2012-2-13 19:45:17的发言:

user库默认是系统库就像我们定义一样。有时候不能用dim Long as string
有道理..
不过楼主,你的语句也需要再修改的
Adodc1.RecordSource = "select * from [user] where username='" & trim((Text2.Text)) & "'"

才能确保正确执行查询语句的,
不信你,你在Text2输入的内容前面加2个空格,看不看能不能查询出什么东西来/..
1