我要把通过query查询出来的一个字段的数据写到combobox中,查询出来怎么朝combobox中写

解决方案 »

  1.   

    query1.first;
    while not query1.eof do
    begin
      combobox1.items.add(query1.fieldbyname('field').asstring)
      query1.next;
    end;
      

  2.   

    with query1 do 
    begin
      sql.text:='select fieldname form tablename where ... ';
      open;
    end;
    while not query1.eof  do 
    begin
      with combobox1.items  do
      begin
        clear;
        add(query1.fieldbyname('fieldname').asstring);    
      end;
      next;
    end;
      

  3.   

    with query1 do 
    begin
      close;
      sql.add('select distinct yourfieldname from yourtablename');
      open;
      first;
      if not eof then
      begin
        combobox1.items.add(fields[0].asstring);
        next;
      end;
    end;
      

  4.   

    anh(hananying) 你的clear位置不对吧
      

  5.   

    是的,我写错了,应放在外面的。
    with query1 do 
    begin
      sql.text:='select fieldname form tablename where ... ';
      open;
    end;
    combobox1.items.clear;
    while not query1.eof  do 
    begin
      with combobox1.items  do
      begin
        add(query1.fieldbyname('fieldname').asstring);    
      end;
      next;
    end;