怎么点Cmd  都没反映DataGrid1.ClearFields
    dbconn.Open "Provider=Microsoft.Jet.OLEDB.4.0;Data source=E:\testpaper\DB\testpaper.mdb"    connstr = "select * from testdes"
    tempsql = connstrIf Not Combo1(0).Text = "" Then
        tempsql = tempsql & " where itemname like '" + Combo1(0).Text + "'"
End IfIf Not Combo1(1).Text = "" Then
    If tempsql <> connstr Then
        tempsql = tempsql & " and sttype like '" + Combo1(1).Text + "'"
    Else
        tempsql = tempsql & " where sttype like '" + Combo1(1).Text + "'"
    End If
End IfIf Not Combo1(2).Text = "" Then
    If tempsql <> sql Then
        tempsql = tempsql & " and ledes like '" + Combo1(2).Text + "'"
    Else
        tempsql = tempsql & " where ledes like '" + Combo1(2).Text + "'"
    End If
End IfDebug.Print tempsql
mrc.Open tempsql, dbconn, adOpenStatic, adLockOptimisticIf Not mrc.EOF Then
    Debug.Print mrc.Fields(0)
End If
 
 mrc.Close
 dbconn.Close

解决方案 »

  1.   

    要加百分号
    tempsql = tempsql & " where ledes like '%" + Combo1(2).Text + "%'"
      

  2.   

    like 'aa%'   '查找以aa开头的内容
    like '%aa'   '查找以aa结束的内容
    like '%aa%'  '查找包含aa的内容
      

  3.   

    我现在改成这样了。本来datagrid最开始显示所有的数据,但选择combobox其中一个或者多个进行查找的时候,datagrid清空,不显示任何数据了。。
        connstr = "select * from testdes"
        tempsql = connstrIf Not Combo1(0).Text = "" Then
            tempsql = tempsql & " where itemname like '%" + Combo1(0).Text + "%'"
    End IfIf Not Combo1(1).Text = "" Then
        If tempsql <> connstr Then
            tempsql = tempsql & " and sttype like '%" + Combo1(1).Text + "%'"
        Else
            tempsql = tempsql & " where sttype like '%" + Combo1(1).Text + "%'"
        End If
    End IfIf Not Combo1(2).Text = "" Then
        If tempsql <> connstr Then
            tempsql = tempsql & " and ledes like '%" + Combo1(2).Text + "%'"
        Else
            tempsql = tempsql & " where ledes like '%" + Combo1(2).Text + "%'"
        End If
    End IfDebug.Print tempsql
    mrc.CursorLocation = adUseClientmrc.Open tempsql, dbconn, adOpenDynamic, adLockBatchOptimisticSet DataGrid1.DataSource = mrcIf Not mrc.EOF Then
        Debug.Print mrc.Fields(0)
    End If
     
     mrc.Close
      

  4.   

            tempsql = tempsql & " where itemname like '%" + Combo1(0).Text + "%'"
    End IfIf Not Combo1(1).Text = "" Then
        If tempsql <> connstr Then
            tempsql = tempsql & " and sttype like '%" + Combo1(1).Text + "%'"
        Else
            tempsql = tempsql & " where sttype like '%" + Combo1(1).Text + "%'"
        End If
    End If
    这种写法有可能会造成一句SQL里有多个WHERE 所以会查不出结果楼主可以在执行SQL前加个断点
    查看一下SQL语句是不是有问题
      

  5.   

    是出错还是没有反应
    请将like '%
    改成like'% 不留空格看看
      

  6.   

    '先写个条件占位符where 1=1 再在后面用and连接
    connstr = "select * from testdes where 1=1 "
    tempsql = connstrIf trim(Combo1(0).Text) <> "" Then
        tempsql = tempsql & " and itemname like '%" &  trim(Combo1(0).Text) & "%'"
    End IfIf trim(Combo1(1).Text) <> "" Then
        tempsql = tempsql & " and sttype like '%" & trim(Combo1(1).Text) & "%'"
    end If
      

  7.   

    还是一样,。datagrid清空 无数据显示!
      

  8.   

    他用的是ACCESS数据库,跟SQL有点不一样的.
    打开你的数据库,出来左边有个窗体,上面有"表","查询","窗体"等,选择"查询"-->"新建"-->出来的窗体"确定"-->再出来的窗体"关闭",不用理会这里,这时在左上角大窗口那里会出现个"SQL",点开他有个"SQL视图",进入这里就可以把你在程序中的SQL语句放到这里来调试了
      

  9.   

    '数据库是ACCESS的话用*代替%试试:
    '先写个条件占位符where 1=1 再在后面用and连接
    connstr = "select * from testdes where 1=1 "
    tempsql = connstrIf trim(Combo1(0).Text) <> "" Then
        tempsql = tempsql & " and itemname like '*" &  trim(Combo1(0).Text) & "*'"
    End IfIf trim(Combo1(1).Text) <> "" Then
        tempsql = tempsql & " and sttype like '*" & trim(Combo1(1).Text) & "*'"
    end If