http://img.jpg.name/wtwhszhdrwvrthhdwjwywvhwrjytwjhzsjyt.jpg在我的界面上的combobox下拉选项中有如下项:all,carton,retailbox,tag,book,others
其中'all'为我在combobox items唯一手工添加上去的选项,其余为adoquery1动态赋值,当我选其中一个选项后,dbgrid能显示只包含此类型项的全部属性(数据表中包含此选项的局部数据)。但我如何可以做到当我选择‘all’之后,dbgrid又能恢复全部显示整个数据表中的内容??? 我的combobox onclick事件代码如下:adoquery1.Close;
adoquery1.SQL.Clear;
adoquery1.SQL.Add('select * from 报价表 where 类型 = '''+combobox1.text+'''');
adoquery1.Open;
adotable1.clone(adoquery1,ltunspecified);
(此代码能显示包含combobox1.text的局部数据,但无法再让dbgrid显示全部表中的数据)
我该添加哪些代码或是组件?? 请帮帮我,谢谢!!!

解决方案 »

  1.   

    1、首先定义一个全局变量
    var 
    str:string;2、
    adoquery1.SQL.Add('select * from 报价表 where 类型 = '''+combobox1.text+'''');
    改为adoquery1.SQL.Add('select * from 报价表'+ str);3、
    在combobox的onchange中写:
    begin
      if combobox1.Text='all' then
       str:='';
       else
       str:='where 类型 = '''+combobox1.text+''''';
    end;
      

  2.   


    var
      SQLStr : String;begin
      SQLStr := 'select * from 报价表 ';
      if (trim(combobox1.text)<> '') and (lowercase(trim(combobox1.text)) <> 'all') then
        SQLStr := 'select * from 报价表 where 类型 = '+ Quotedstr(combobox1.text);
      adoquery1.Close; 
      adoquery1.SQL.Clear; 
      adoquery1.SQL.text := SQLStr ;
      adoquery1.Open; 
      adotable1.clone(adoquery1,ltunspecified); 
    end
      

  3.   


    在你原来的代码上改的。
    var
      sWhere:string;
    begin
      if lowercase(trim(combobox1.text))='all' then
        sWhere:='' else
        sWhere:=' and 类型='''+trim(combobox1.text)+'''';
      adoquery1.Close; 
      adoquery1.SQL.Clear; 
      adoquery1.SQL.Add('select * from 报价表 where 1=1'+sWhere); 
      adoquery1.Open; 
      adotable1.clone(adoquery1,ltunspecified);
    end;
      

  4.   

    var
      sqlstr : string;
    begin
      sqlstr := 'select * from 报价表 where 1=1';
      if trim(combobox1.text)<> 'all' then
        sqlstr := sqlstr + ' and 类型='+quotedstr(combobox1.text);
      with adoquery1 do
      begin
        close;
        sql.clear;
        sql.add(sqlstr);
        open;
      end;
    end;
      

  5.   

    楼上全是正解,在用ALL时就需加一条件判断,即:var 
      sSQL:string;
    if combobox1.ItemIndex<>0 then
      sSQL:= 'SELECT * FROM 报价表 where 类型='+ Quotedstr(combobox1.text)
    else sSQL:= 'SELECT * FROM 报价表; 
      
      

  6.   

    'select * from 报价表 where 类型 = '''+combobox1.text+''' or ''all'' = '''+combobox1.text'+''''
      

  7.   

    'select * from 报价表 where 类型 = '''+combobox1.text+''' or ''all'' = '''+combobox1.text+''''