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/07/05 00:45:46
![dim strsql as stringIf Text1.Text](/uploads/image/z/2565481-49-1.jpg?t=dim+strsql+as+stringIf+Text1.Text+%22%22+ThenAdodc1.Recordset.CloseIf+Val%28Text1.Text%29+0+Thenstrsql+%3D+%22select+%2A+from+name+where+name%3D%22+%26+Trim%28Text1.Text%29+%27Trim%E5%8E%BB%E6%8E%89%E5%89%8D%E5%90%8E%E7%A9%BA%E6%A0%BCElsestrsql+%3D+%22select+%2A+from+name+where+name%3D%27%22+%26+Trim%28Text1.Text%29+%26+%22%27%22End+IfA)
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在数据库中是字符串的所有必须加上单引号.