作业帮 > 综合 > 作业

还是不明白哪里出错了,可以帮我看看吗?

来源:学生作业帮 编辑:灵鹊做题网作业帮 分类:综合作业 时间:2024/05/08 15:38:54
还是不明白哪里出错了,可以帮我看看吗?
Private Sub Command1_Click()
Dim strsql As String
If Text1.Text "" Then
Adodc1.Recordset.Close
If Val(Text1.Text) > 0 Then
strsql = "select * from name where name='" & Trim(Text1.Text) & "'"
End If
Adodc1.CommandType = adCmdText
Adodc1.Recordset.Open strsql
Set DataGrid1.DataSource = Adodc1
Else
Set DataGrid1.DataSource = Nothing
End If
End Sub
我在text1裏输入的数字可以收索并显示出来,但输入的是文字就报错
说这句有问题Adodc1.Recordset.Open strsql
我想实现无论输入什麼都可以收索并显示出来,十分感激
还是不明白哪里出错了,可以帮我看看吗?
Private Sub Command1_Click()
Dim strsql As String
If Text1.Text "" Then
Adodc1.Recordset.Close
strsql = "select * from name where name='" & Trim(Text1.Text) & "'"
Adodc1.CommandType = adCmdText
Adodc1.Recordset.Open strsql
Set DataGrid1.DataSource = Adodc1
Else
Set DataGrid1.DataSource = Nothing
End If
End Sub
把内层的If Then去掉.
你要的条件是Name,看来是一个文本,那么你判断数字( If Val(Text1.Text) > 0)做什么用?