如果你查询的是字符型数据,可以使用关键字Like,给你一个例句: strSQL = "select * from 数据表名 where " & Combo1.Text & " like '%" & Text1.Text & "%'" like '%" & Text1.Text & "% 是模糊查询,例如你查询的是“高等数学”,你只要输入“高“ 或 “ 等“ 或 “ 数“ 或 “学“ 中的任何一个字,都可以查询出来。
Private Sub Command1_Click() If Combo1.Text = "教材名" Then Adodc2.RecordSource = "select * from 教材信息 where 教材名 like'%" & Text1.Text & "%'" Adodc2.Refresh DataGrid1.Refresh Set DataGrid1.DataSource = Adodc2 DataGrid1.Visible = True If Adodc2.Recordset.RecordCount > 0 Then Else MsgBox "输入错误,请重新输入!!!" End IfElse: Combo1.Text = "出版社" Adodc2.RecordSource = "select * from 教材信息 where 出版社 like'%" & Text1.Text & "%'" Adodc2.Refresh DataGrid1.Refresh Set DataGrid1.DataSource = Adodc2 DataGrid1.Visible = True If Adodc2.Recordset.RecordCount > 0 Then Else MsgBox "输入错误,请重新输入!!!" End If End IfEnd Sub现在问题就是我输入高等数或高等都可以查到高等数学,但输入高数就查询不了,不知在没解决
Private Sub Command1_Click() If Combo1.Text = "教材名" Then Adodc2.RecordSource = "select * from 教材信息 where 教材名 like'%" & Text1.Text & "%'" Adodc2.Refresh DataGrid1.Refresh Set DataGrid1.DataSource = Adodc2 DataGrid1.Visible = True If Adodc2.Recordset.RecordCount > 0 Then Else MsgBox "输入错误,请重新输入!!!" End IfElse: Combo1.Text = "出版社" Adodc2.RecordSource = "select * from 教材信息 where 出版社 like'%" & Text1.Text & "%'" Adodc2.Refresh DataGrid1.Refresh Set DataGrid1.DataSource = Adodc2 DataGrid1.Visible = True If Adodc2.Recordset.RecordCount > 0 Then Else MsgBox "输入错误,请重新输入!!!" End If End IfEnd Sub现在问题就是我输入高等数或高等都可以查到高等数学,但输入高数就查询不了,不知在没解决 一定要这样的话: Dim strWhere As String Dim i As IntegerFor i = 1 To Len(Text1) strWhere = strWhere & " 出版社 like'%" & Mid(Text1, i, 1) & "%'" If i < Len(Text1) Then strWhere = strWhere & " AND" Next i Adodc2.RecordSource = "select * from 教材信息 where" & strWhere例如输入“高教”时得到的是Adodc2.RecordSource = "select * from 教材信息 where 出版社 like'%高%' AND 出版社 like'%教%'" 可查询到“高等教育出版社”。
Private Sub Command1_Click() If Combo1.Text = "教材名" Then Adodc2.RecordSource = "select * from 教材信息 where 教材名 like'%" & Text1.Text & "%'" Adodc2.Refresh DataGrid1.Refresh Set DataGrid1.DataSource = Adodc2 DataGrid1.Visible = True If Adodc2.Recordset.RecordCount > 0 Then Else MsgBox "输入错误,请重新输入!!!" End IfElse: Combo1.Text = "出版社" Adodc2.RecordSource = "select * from 教材信息 where 出版社 like'%" & Text1.Text & "%'" Adodc2.Refresh DataGrid1.Refresh Set DataGrid1.DataSource = Adodc2 DataGrid1.Visible = True If Adodc2.Recordset.RecordCount > 0 Then Else MsgBox "输入错误,请重新输入!!!" End If End IfEnd Sub现在问题就是我输入高等数或高等都可以查到高等数学,但输入高数就查询不了,不知在没解决 一定要这样的话: Dim strWhere As String Dim i As IntegerFor i = 1 To Len(Text1) strWhere = strWhere & " 出版社 like'%" & Mid(Text1, i, 1) & "%'" If i < Len(Text1) Then strWhere = strWhere & " AND" Next i Adodc2.RecordSource = "select * from 教材信息 where" & strWhere例如输入“高教”时得到的是Adodc2.RecordSource = "select * from 教材信息 where 出版社 like'%高%' AND 出版社 like'%教%'" 可查询到“高等教育出版社”。 但这样我只能输入高教啊,其他的都输入不了
Private Sub Command1_Click() If Combo1.Text = "教材名" Then Adodc2.RecordSource = "select * from 教材信息 where 教材名 like'%" & Text1.Text & "%'" Adodc2.Refresh DataGrid1.Refresh Set DataGrid1.DataSource = Adodc2 DataGrid1.Visible = True If Adodc2.Recordset.RecordCount > 0 Then Else MsgBox "输入错误,请重新输入!!!" End IfElse: Combo1.Text = "出版社" Adodc2.RecordSource = "select * from 教材信息 where 出版社 like'%" & Text1.Text & "%'" Adodc2.Refresh DataGrid1.Refresh Set DataGrid1.DataSource = Adodc2 DataGrid1.Visible = True If Adodc2.Recordset.RecordCount > 0 Then Else MsgBox "输入错误,请重新输入!!!" End If End IfEnd Sub现在问题就是我输入高等数或高等都可以查到高等数学,但输入高数就查询不了,不知在没解决 一定要这样的话: Dim strWhere As String Dim i As IntegerFor i = 1 To Len(Text1) strWhere = strWhere & " 出版社 like'%" & Mid(Text1, i, 1) & "%'" If i < Len(Text1) Then strWhere = strWhere & " AND" Next i Adodc2.RecordSource = "select * from 教材信息 where" & strWhere例如输入“高教”时得到的是Adodc2.RecordSource = "select * from 教材信息 where 出版社 like'%高%' AND 出版社 like'%教%'" 可查询到“高等教育出版社”。 不好意思,看错了。恩可以解决
strSQL = "select * from 数据表名 where " & Combo1.Text & " like '%" & Text1.Text & "%'"
like '%" & Text1.Text & "% 是模糊查询,例如你查询的是“高等数学”,你只要输入“高“ 或 “ 等“ 或 “ 数“ 或 “学“ 中的任何一个字,都可以查询出来。
If Combo1.Text = "教材名" Then
Adodc2.RecordSource = "select * from 教材信息 where 教材名 like'%" & Text1.Text & "%'"
Adodc2.Refresh
DataGrid1.Refresh
Set DataGrid1.DataSource = Adodc2
DataGrid1.Visible = True
If Adodc2.Recordset.RecordCount > 0 Then
Else
MsgBox "输入错误,请重新输入!!!"
End IfElse: Combo1.Text = "出版社"
Adodc2.RecordSource = "select * from 教材信息 where 出版社 like'%" & Text1.Text & "%'"
Adodc2.Refresh
DataGrid1.Refresh
Set DataGrid1.DataSource = Adodc2
DataGrid1.Visible = True
If Adodc2.Recordset.RecordCount > 0 Then
Else
MsgBox "输入错误,请重新输入!!!"
End If
End IfEnd Sub现在问题就是我输入高等数或高等都可以查到高等数学,但输入高数就查询不了,不知在没解决
If Combo1.Text = "教材名" Then
Adodc2.RecordSource = "select * from 教材信息 where 教材名 like'%" & Text1.Text & "%'"
Adodc2.Refresh
DataGrid1.Refresh
Set DataGrid1.DataSource = Adodc2
DataGrid1.Visible = True
If Adodc2.Recordset.RecordCount > 0 Then
Else
MsgBox "输入错误,请重新输入!!!"
End IfElse: Combo1.Text = "出版社"
Adodc2.RecordSource = "select * from 教材信息 where 出版社 like'%" & Text1.Text & "%'"
Adodc2.Refresh
DataGrid1.Refresh
Set DataGrid1.DataSource = Adodc2
DataGrid1.Visible = True
If Adodc2.Recordset.RecordCount > 0 Then
Else
MsgBox "输入错误,请重新输入!!!"
End If
End IfEnd Sub现在问题就是我输入高等数或高等都可以查到高等数学,但输入高数就查询不了,不知在没解决
一定要这样的话:
Dim strWhere As String
Dim i As IntegerFor i = 1 To Len(Text1)
strWhere = strWhere & " 出版社 like'%" & Mid(Text1, i, 1) & "%'"
If i < Len(Text1) Then strWhere = strWhere & " AND"
Next i
Adodc2.RecordSource = "select * from 教材信息 where" & strWhere例如输入“高教”时得到的是Adodc2.RecordSource = "select * from 教材信息 where 出版社 like'%高%' AND 出版社 like'%教%'"
可查询到“高等教育出版社”。
If Combo1.Text = "教材名" Then
Adodc2.RecordSource = "select * from 教材信息 where 教材名 like'%" & Text1.Text & "%'"
Adodc2.Refresh
DataGrid1.Refresh
Set DataGrid1.DataSource = Adodc2
DataGrid1.Visible = True
If Adodc2.Recordset.RecordCount > 0 Then
Else
MsgBox "输入错误,请重新输入!!!"
End IfElse: Combo1.Text = "出版社"
Adodc2.RecordSource = "select * from 教材信息 where 出版社 like'%" & Text1.Text & "%'"
Adodc2.Refresh
DataGrid1.Refresh
Set DataGrid1.DataSource = Adodc2
DataGrid1.Visible = True
If Adodc2.Recordset.RecordCount > 0 Then
Else
MsgBox "输入错误,请重新输入!!!"
End If
End IfEnd Sub现在问题就是我输入高等数或高等都可以查到高等数学,但输入高数就查询不了,不知在没解决
一定要这样的话:
Dim strWhere As String
Dim i As IntegerFor i = 1 To Len(Text1)
strWhere = strWhere & " 出版社 like'%" & Mid(Text1, i, 1) & "%'"
If i < Len(Text1) Then strWhere = strWhere & " AND"
Next i
Adodc2.RecordSource = "select * from 教材信息 where" & strWhere例如输入“高教”时得到的是Adodc2.RecordSource = "select * from 教材信息 where 出版社 like'%高%' AND 出版社 like'%教%'"
可查询到“高等教育出版社”。
但这样我只能输入高教啊,其他的都输入不了
If Combo1.Text = "教材名" Then
Adodc2.RecordSource = "select * from 教材信息 where 教材名 like'%" & Text1.Text & "%'"
Adodc2.Refresh
DataGrid1.Refresh
Set DataGrid1.DataSource = Adodc2
DataGrid1.Visible = True
If Adodc2.Recordset.RecordCount > 0 Then
Else
MsgBox "输入错误,请重新输入!!!"
End IfElse: Combo1.Text = "出版社"
Adodc2.RecordSource = "select * from 教材信息 where 出版社 like'%" & Text1.Text & "%'"
Adodc2.Refresh
DataGrid1.Refresh
Set DataGrid1.DataSource = Adodc2
DataGrid1.Visible = True
If Adodc2.Recordset.RecordCount > 0 Then
Else
MsgBox "输入错误,请重新输入!!!"
End If
End IfEnd Sub现在问题就是我输入高等数或高等都可以查到高等数学,但输入高数就查询不了,不知在没解决
一定要这样的话:
Dim strWhere As String
Dim i As IntegerFor i = 1 To Len(Text1)
strWhere = strWhere & " 出版社 like'%" & Mid(Text1, i, 1) & "%'"
If i < Len(Text1) Then strWhere = strWhere & " AND"
Next i
Adodc2.RecordSource = "select * from 教材信息 where" & strWhere例如输入“高教”时得到的是Adodc2.RecordSource = "select * from 教材信息 where 出版社 like'%高%' AND 出版社 like'%教%'"
可查询到“高等教育出版社”。
不好意思,看错了。恩可以解决
如果你必须这样查询,只能拆散字符,然后分别查询。