这个界面是教材查询,我用的是adodc连接的数据库,然后我想实现的是快速查询,即:首先选择一个查询方式,后面关键字再根据的前面查询方式输入(比如查询方式为教材名,输入关键字就为教材名),最后通过查询在查询结果里显示。

解决方案 »

  1.   

    Adodc1.RecordSource = "Select * from 表名 where " & Combo1.Text & " like'%" & Text1.Text & "%'"
      

  2.   

    这个问题不是一句就可以解决的,因为,你点击Combo1后,实际上是查询这个字段的查询条件,但一个数据表各字段的数据类型不同,因此查询的方式也是不同的,需要根据字段的数据类型设置不同的查询方式,例如字符型数据,可以使用 Leke 的关键字,但数字类型的数据、日期类型数据等就不能使用这个关键字,今天有点事,不能给你例子,晚上做一个给你吧。
      

  3.   

    对不起!刚刚打错了,Like打成Leke了。
      

  4.   

    如果你查询的是字符型数据,可以使用关键字Like,给你一个例句:
    strSQL = "select * from 数据表名 where " & Combo1.Text & " like  '%" & Text1.Text & "%'"
     like  '%" & Text1.Text & "% 是模糊查询,例如你查询的是“高等数学”,你只要输入“高“   或  “ 等“   或  “ 数“   或   “学“ 中的任何一个字,都可以查询出来。
      

  5.   

    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现在问题就是我输入高等数或高等都可以查到高等数学,但输入高数就查询不了,不知在没解决
      

  6.   

    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'%教%'"
    可查询到“高等教育出版社”。
      

  7.   

    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'%教%'"
    可查询到“高等教育出版社”。
    但这样我只能输入高教啊,其他的都输入不了
      

  8.   

    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'%教%'"
    可查询到“高等教育出版社”。
    不好意思,看错了。恩可以解决
      

  9.   

    SQL语句的Like关键字的模糊查询,只能查询记录中连续的字符串,不能查询不连续的字符,由于你的记录是高等数学,连续的二个字符串有:高等、等数、数学,连续的三个字符串有高等数、等数学,这些都能够查询到,但不连续的字符串,例如:高数、等学,肯定查询不到的,对于单字符根本没有问题,可以查询到。
    如果你必须这样查询,只能拆散字符,然后分别查询。