我想问一下,我如何用dblookupcombobox1,dblookupcombobox2和两个时间之间(datatimepicker)共同来对dbgrid进行检索?我知道,如果是一个条件的话,是这样的:
begin
  with ADOTable2 do
  begin
    close;
    filtered:=false;
    Filter := '配件名称=''' + dblookupComboBox1.Text + '''';
    Filtered := true;
    open;
  end
end;但是多个条件的话该怎么办呢?and好象一直在报错请高手指点啊

解决方案 »

  1.   

    filter其实就是sql语句中的where部分
      with tbl1 do
      begin
        close;
        filtered:=false;
        Filter := 'name = ''' + edt1.Text + '''' + ' and swx=' + '''test''';
        Filtered := true;
        open;
      end;
      

  2.   

    把where后面的直接拿出来给filter
    没有查询结果就是没有匹配的。你最好在sql查询器里先测下。另建议你用ADOQuerysqltr := 'select * from a where name = ''' + edt1.Text + '''' + ' and swx=' 
             + '''test'' and data1 >=' + '''2008-09-21''' + ' and data2 <=' + '''2009-01-01''';
      

  3.   

    begin
    with form4.ADOTable1 do
      begin
        close;
        filtered:=false;   Filter :='配件名称=''' + dblookupComboBox1.Text + ''''+
        ' and '入库单位=''' + dblookupComboBox1.Text + ''''+ and
          '入库时间>='''+datetimepicker1.datetime+'''+
          ' and '入库时间<='''+datetimepicker2.datetime+''';    Filtered := true;
        open;
      endend;
    上面这段帮我找下错误,我一直运行不下去?
      

  4.   

    Filter :='配件名称=''' + dblookupComboBox1.Text + ''''
             + ' and 入库单位=''' + dblookupComboBox1.Text + ''''
             + ' and 入库时间>=''' + datetimepicker1.datetime + ''''
             + ' and 入库时间<=''' + datetimepicker2.datetime + '''';
      

  5.   

      上面忘了把时间转为字符串了
      Filter :='配件名称=''' + dblookupComboBox1.Text + ''''
             + ' and 入库单位=''' + dblookupComboBox1.Text + ''''
             + ' and 入库时间>=''' + DateTimeToStr(datetimepicker1.datetime) + ''''
             + ' and 入库时间<=''' + DateTimeToStr(datetimepicker2.datetime) + '''';如果数据库是access
      Filter :='配件名称=''' + dblookupComboBox1.Text + ''''
             + ' and 入库单位=''' + dblookupComboBox1.Text + ''''
             + ' and 入库时间>=#' + DateTimeToStr(datetimepicker1.datetime) + '#'
             + ' and 入库时间<=# + DateTimeToStr(datetimepicker2.datetime) + '#';
      

  6.   

    可以了 ,我数据库是ACCESS,但用的是你上面那个方法,就是不加#的。谢谢yinxd6112