比如说 之前已近建立了一个数据库 表名为aa,4个字段:
 ID, 品名, 产地, 数量 
 1    苹果   新疆    20
 2    军刀   大陆    2
 3    苹果   美国    30
 4    油条   弄堂    5
 5    剪刀   大陆    10
 6    大饼   弄堂    10连接方式是 ConnectString = "provider=Microsoft.Jet.OLEDB.4.0;Data source ="  & App.Path & "/db1.mdb"问题就是想要做个筛选功能键, 品名(text1),产地(text2), 数量(text3)
在对应的text中输入筛选的条件,比如说 在品名里输入 苹果 ,按筛选
然后能在我的DataGrid控件中能够出现:
品名, 产地, 数量 
苹果   新疆    20
苹果   美国    30在产地里输入 大陆 控件中能够出现
品名, 产地, 数量
军刀   大陆    2
剪刀   大陆    10请帮忙做一个代码

解决方案 »

  1.   

    就select 下么?
    refresh就行
      

  2.   

    由于对VB布什很熟悉  想知道对数据库筛选出来的内容 应该在VB中的什么控件中显示好? 而且该控件最好还有对每个字段的 排序功能
      

  3.   

    http://download.csdn.net/source/1498324
    http://download.csdn.net/source/1644211
      

  4.   

    adodc + datagrid
    adodc 指定驱动路径和select语句
    datagrid.datasouse=adodc
    需要重新查询时
    adodc刷新
      

  5.   

    窗体上添加三个文本框,两个命令按钮,一个MSHFlexgrid控件,一个ADODC控件。
    添加以下代码Dim paixu  As BooleanPrivate Sub Command1_Click()
        Dim strA As String
        strA = ""
        If Text1.Text <> "" Then
            strA = " where 品名 = '" & Text1.Text & "'"
        End If
        If Text2.Text <> "" Then
            If strA = "" Then
                strA = strA & " where 产地 = '" & Text2.Text & "'"
            Else
                strA = strA & " and 产地 =  '" & Text2.Text & "'"
            End If
        End If
        If Text3.Text <> "" Then
            If strA = "" Then
                strA = strA & " where 数量 =  " & Text3.Text
            Else
                strA = strA & " and 数量 = " & Text3.Text
            End If
        End If
        If strA = "" Then
            Adodc1.RecordSource = "select * from aa " & strA & " order by id"
            Adodc1.Refresh
            If Adodc1.Recordset.RecordCount < 0 Then
           
                MsgBox "没有找到匹配的记录!", , "提示窗口"
            End If
        Else
            Adodc1.RecordSource = "select * from aa " & strA & " order by id"
            Adodc1.Refresh
        End If
    End Sub
                                                                                                                                                      
    Private Sub Command2_Click()
     Adodc1.RecordSource = "select * from aa  order by id"
            Adodc1.Refresh
    End SubPrivate Sub Form_Load()
        Me.Caption = Text
        Adodc1.ConnectionString = "provider=Microsoft.Jet.OLEDB.4.0;Data source =" & App.Path & "/db1.mdb"
        Adodc1.RecordSource = "select * from aa order by ID "
        Adodc1.Refresh
        Set MS1.DataSource = Adodc1
    End Sub
                                                                             
    Private Sub Ms1_Click()
     '单击固定行排序
        If MS1.MouseRow >= 0 And MS1.MouseRow < MS1.FixedRows Then
            If paixu = True Then
                MS1.Sort = 1
                paixu = False
            Else
                MS1.Sort = 2
                paixu = True
            End If
        End If
    End Sub
      

  6.   

    十分感谢你的代码 已测试  很实用但还有个问题麻烦解答下 
     就是 当一些内容被筛选出以后  我想通过MSHFlexgrid控件 对数据直接进行一些修改,然后保存 
    这些能做到吗
      

  7.   

    if text1.text<>"" then
       Adodc1.RecordSource ="select * from aa where 品名='"& text1.text &"'"
       Adodc1.refresh
       set DataGrid1.datasource=Adodc1.Rrcordset
    elseif text2.text<>"" then
       Adodc1.RecordSource ="select * from aa where 产地='"& text2.text &"'"
       Adodc1.refresh
       set DataGrid1.datasource=Adodc1.Rrcordset
    elseif 
       Adodc1.RecordSource ="select * from aa where 数量=" & val(text3.text)
       Adodc1.refresh
       set DataGrid1.datasource=Adodc1.Rrcordset
    endif
      

  8.   

    没有用到hav子句怎么叫筛选呢?
    怎么都是采用控件连接啊
    以后你会觉得觉得控件连接麻烦,为什么不采用字符串连接呢?
      

  9.   

    Adodc1.ConnectionString = "provider=Microsoft.Jet.OLEDB.4.0;Data source =" & App.Path & "/db1.mdb"
    怎么都是采用控件连接啊 
    以后你会觉得觉得控件连接麻烦,为什么不采用字符串连接呢?使用DataEnvironment设计器做的连接有什么区别