在VB中对数据的查询!

来源:百度知道 编辑:UC知道 时间:2024/06/22 12:05:29
在窗体上有一个combo1、text1、datagrid1、adodc1和按钮,请高手指点,代码如下:Option ExplicitDim str As String
Private Sub Command1_Click()
If Combo1.Text = 姓名 Then
str = "selecte * form yggli where 姓名=" & "" & Val(Text1.Text) & ""
Adodc1.RecordSource = str
Adodc1.Refresh
If Adodc1.Recordset.RecordCount > 0 Then
MsgBox "已经找到这条记录!"
DataGrid1.DataSource = Adodc1
Else
MsgBox "没有找到这条记录!"
Adodc1.Refresh
DataGrid1.Refresh
End If
ElseIf Combo1.Text = 编号 Then
str = "selecte * form yggli where 编号=" & "" & Val(Text1.Text) & ""
Adodc1.RecordSource = str
Adodc1.Refresh
If Adodc1.Recordset.RecordCount > 0 Then
MsgBox "已经找到这条记录!"
Else
MsgBox "没有找到这条记录!"
Adodc1.Refresh
DataGrid1.Refresh
End If
End If
End Sub
现在又说变量未定义,是指向“姓名”

??有错误?什么错误?

可以肯定的是。就是DataGrid1.DataSource = Adodc1的问题。
你可以写成。
set DataGrid1.DataSource = Adodc1
估计就没有问题了。

str = "selecte * form yggli where 姓名=" & "" & Val(Text1.Text) & ""

str = "selecte * form yggli where 编号=" & "" & Val(Text1.Text) & ""

查询姓名和编号都用Text1.text里的内容?

str = "selecte * form yggli where 姓名=" & "" & Val(Text1.Text)
^
姓名有可能是数值吗
应删除 VAL 涵数