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 IfA

来源:学生作业帮助网 编辑:作业帮 时间:2024/04/29 07:27:19

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 IfA
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
以上查找字母或中文都不会报错,但查找的为数字就会报错”标准表达式中数据类型不匹配“

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