我建立了一个empleror表,字段:姓名、性别、部门、职位。
在form中用了两个combo和一个text框,要求对其中一个字段进行查询时,查询结果
在datagrid中显示,请写出查询代码!好的话,100分全给你,不够再加!

解决方案 »

  1.   

    rs.open "select 姓名 from empleror where 姓名='"& trim(text1.text) &"',cnn,adOpenDynamic, adLockPessimistic
    set datagrid.datasource=rs
      

  2.   

    combo和text是用来生成查询条件的,If Combo1.Text <> "" And Combo2.Text <> "" And Text3.Text <> "" Then
    tab1 = Combo1.Text
    tab2 = Combo2.Text
    tab3 = Text3.Text
    strSQL = "Select * From Empleror Where" & " " & tab1 & tab2 & tab3
    Text2.Text = strSQLAdodc1.Recordset.Open strSQL
    Adodc1.Refresh
    Set DataGrid.DataSource = Adodc1.Recordset
        DataGrid.Refresh
    运行后提示错误:如果对象已经打开,则不允许应用程序所要求的操作。
      

  3.   

    关于如何使ADODB.Recordset对象与Datagrid.DataSource属性绑定,楼主可以参考下面的帖子。http://expert.csdn.net/Expert/topic/1555/1555609.xml?temp=.4775202
      

  4.   

    你查询的条件是什么?tab1,tab2,tab3只是筛选条件的内容。
    另外,直接将SQL语句赋值给Adodc1.RecordSource属性,然后Adodc1.Refresh.还有Set DataGrid.DataSource=Adodc1即可,不需要指定.Recordset
      

  5.   

    rs.open "select 姓名 from empleror where 姓名='"& trim(text1.text) &" and 字段='"& tab3 &"' and 字段='"& tab2 &"'',cnn,adOpenDynamic, adLockPessimistic
    set datagrid.datasource=rs
      

  6.   

    是通过tab1,tab2,tab3筛选条件后,生成SQL语句,再将语句赋给strSQL进行查询。
      

  7.   

    是通过tab1,tab2,tab3筛选条件后,生成SQL语句,再将语句赋给strSQL进行查询。
    查询条件就是通过生成的,简单的说,就是要进行任意单条件查询。
      

  8.   

    dim tmp_name     as strng
    dim tmp_sex      as string
    dim tmp_job      as string
    dim strsql       as string
    dim tmprs        as new adodb.recordset
     
    if trim(text1.text)<>"" then
        tmp_name=" and 姓名='"& text1.text &"'"
    else
        tmp_name=""
    endif
    if trim(text2.text)<>"" then
        tmp_sex=" and 性别='"& text2.text &"'"
    else
        tmp_sex=""
    endif
    if trim(text3.text)<>"" then
        tmp_job=" and 职位='"& text3.text &"'"
    else
        tmp_job=""
    end ifstrsql=" select * from employee where 1=1 " & tmp_name & tmp_sex & tmp_jobif tmprs.state=adstateopen then tmprs.close
    tmprs.open strsql,conn,adopenkeyset,adlockreadonlyset datagrid.datasource=tmprsset tmprs=nothing
      

  9.   

    to (leftie)
    “strsql=" select * from employee where 1=1 " & tmp_name & tmp_sex & tmp_job”
    一句我不太懂,能解释一下吗?
      

  10.   

    因为用户的输入条件是不固定的,有可能全部输入,也有可能一个都不输入
    所以如果你把"where"写入到哪里就很难判断(特别是有四个以上的用户输入条件时),如果按照的我方法,用户输入条件则某一变量为" and ...",否则为"",这样连成的语句为:
     "select * from tablename where 1=1"  或
     "select * from tablename where 1=1 and ... and ..."
      

  11.   

    非常感谢Leftie(Leftie) 兄,也谢谢其他大虾,以后请多指教,我会尽快结贴。
      

  12.   

    Leftie(Leftie) 兄,你的“tmprs.Open strsql, conn, adOpenKeyset, adLockReadOnly”一句在运行市显示:“应用程序使用的参数或类型不正确,或者不在可以接受的范围之内,要不就是与其他数据冲突。”请问问题出在哪儿?
      

  13.   

    试试tmprs.Open strsql, conn, 1, 1
      

  14.   

    Adodc1.Recordset.Open "select * from empleror where " & combo1.text & " " &_    
                          & combo2.text & "'" & text1.text & "'"
    Adodc1.Refresh
    Set DataGrid.DataSource = Adodc1.Recordset
    DataGrid.Refresh