dim strsql as stringIf Text1.Text "" ThenAdodc1.Recordset.CloseIf Val(Text1.Text) 0 Thenstrsql = "select * from name where name=" & Trim(Text1.Text) 'Trim去掉前后空格Elsestrsql = "select * from name where name='" & Trim(Text1.Text) & "'"End IfAdodc1.CommandType = adCmdTextAdodc1.Recordset.Open strsqlSet DataGrid1.DataSource = Adodc1ElseSet DataGrid1.DataSource = NothingEnd If以上查找字母或中文都不会报错,但查找的为数字就会报错”标准表达式中数据类型不匹配“

问题描述:

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) 'Trim去掉前后空格
Else
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
以上查找字母或中文都不会报错,但查找的为数字就会报错”标准表达式中数据类型不匹配“

strsql = "select * from name where name=" & Trim(Text1.Text) 'Trim去掉前后空格你这个name在数据库中是字符串的所有必须加上单引号.