怎样用ADOQuery实现动态查询?
即:随着查询条件的输入,显示的数据范围不断缩小!

解决方案 »

  1.   

    太慢了吧
    每次修改sql,打开,效率低
      

  2.   

    判断查询条件输入框变化,用ONCHANGE事件,然后一变化就调用查询。PS:好像效率不高,反复查询数据库。耗资源
      

  3.   

    用一下FILTER过滤数据看行不行还可以用ADOQUERY 的PARMETERS来设定变量
      

  4.   

    建议用filter,如果反复用sql语句提取数据,会增加网络负担
    可以每增加一个条件,过滤条件详细一些,这样也能达到你的要求的效果
      

  5.   

    如果数据变得很小的话可以放在本地。如省份,城市等数据库。
    动态改变where就行了。很简单的。
      

  6.   

    我有一个不过太垃圾了,你可以参考一下  
    sqlstring:='select * from zjdj where';
     begin
      if combobox1.Text = '等于' then
        begin
          if combobox2.Text = '专家编号' then
            begin
              a1:=' zjbh='''+trim(edit1.Text)+'''and';end;
          if combobox2.Text = '姓名' then
            begin
              a2:=' xm='''+trim(edit1.Text)+'''and';
            end;
          if combobox2.Text = '性别' then
            begin
              a3:=' xb='''+trim(edit1.Text)+'''and';
            end;
    .......
    sqlstring:=sqlstring+a1+a2+a3+.........
    copy(sqlstring,1,length(sqlstring)-3)//去掉最后一个end;
    adoquery.sql.add(sqlstring);
    adoquery.open;
      

  7.   

    If Combobox4.Text <> '' Then
      Searchstr1 := 'landname like ''%'+Combobox4.Text +'%'' and  '
    Else
      Searchstr1 := '';
    If edit4.Text = '0' Then
      Searchstr2 := ''
    Else
      Searchstr2 := '(precativeprince>='''+edit3.Text+'''  and precativeprince<='''+edit4.Text+''') and ';If Combobox5.Text <> '' Then
      Searchstr4 := '(housetype='''+ Combobox5.Text +''')  and '
    Else
      Searchstr4 :='';If Combobox1.Text <> '' Then
      Searchstr5 := '(inputtype='''+ Combobox1.Text +''') and '
    Else
      Searchstr5 := '';If Combobox2.Text <> '' Then
      Searchstr7 := '(cityfield=''' + Combobox2.Text +''') and '
    Else
      Searchstr7 := '';If Combobox3.Text <> '' Then
      Searchstr8 := '(childfield='''+ Combobox3.Text + ''') and '
    Else
      Searchstr8 := '';If edit1.Text = '' Then
      edit1.Text := '0';
    If edit2.Text = '' Then
      edit2.Text := '0';If edit2.Text = '0' Then
      Searchstr6 := ''
    Else    Searchstr6 := '(area>='''+ edit1.Text+''' and area<='''+ edit2.Text +''') and ';
    Searchstr := Searchstr1 + Searchstr2 + Searchstr3 + Searchstr4 + Searchstr5 +Searchstr6 + Searchstr7 + Searchstr8 ;这样效率高得多
      

  8.   

    一次Open,然后在OnChange里写Filter过滤条件!
      

  9.   

    关键在于构造好你的动态sql语句
      

  10.   

    首先用sql查询出所有的记录,再在edit1的onchange事件里写上对query1的Filter过滤条件即可。