怎么把sql中:'select fdept from employee group by fdept'找到的记录,赋给combobox2???
应在那里写?procedure TForm_xjquery.Button1Click(Sender: TObject);
begin
adoquery1.SQL.clear;
adoquery1.sql.Add('select fdept from employee group by fdept');
adoquery1.open;
ComboBox2.Items.Add(??????);
end;

解决方案 »

  1.   

    adoquery2.first;
    while not adoquery1.eof  do 
      begin 
       combobox2.clear;
       combobox2.items.add.(adoquery1.fieldbyname('fdept').asstring);
       adoquery2.next;end;---------------------------------
    是不是这样要求?
      

  2.   

    你是要把所有的记录都加到combobox中去吗,如果是要加所有的记录的话,楼上的那个语句就得改一下,
    combobox2.clear; 
    adoquery2.first; 
    while not adoquery1.eof   do  
      begin  
       combobox2.items.add.(adoquery1.fieldbyname('fdept').asstring); 
       adoquery2.next; 
    end; 
    要不然的话你每执行一次,又清空了cobobox一次,那执行完之后combobox中显示的就会是最后一条记录。
      

  3.   

    procedure TForm_xjquery.Button1Click(Sender: TObject); 
    begin 
      with adoquery1 do
      begin
        SQL.Clear; 
        SQL.Add('select fdept from employee group by fdept'); 
        Open;
        Combobox2.Clear;
        while not eof do
        begin
          Combobox2.items.add(fieldbyname('fdept').asstring);
          Next;
        end;
        Close;
      end; 
    end;
      

  4.   

    'select fdept from employee group by fdept'这条sql语句如何处理可以去掉空的记录结果如下:
    fdept生管部
    总经办
    生技部
    品管部
    高层管理
    管理部
    品证部
    制造部
    技术部其中有一个结果为空白的,如何去掉那些空白的记录可以得到以下记录?
    ================================
    可想要的结果为:
    fdept
    生管部
    总经办
    生技部
    品管部
    高层管理
    管理部
    品证部
    制造部
    技术部
      

  5.   

    select fdept from employee where fdept<>''  group by fdept
      

  6.   

    group by 不是这么用法的,虽然可以达到目的。通常是这样:
    select distinct fdept from employee where fdept is not null
    用3楼的方法添加数据后,再加上这句会好一点,让它显示第一条数据:
    ComboBox2.Text:=ComboBox2.Items[0];