我是一个delphi初学者,我想把数据库里面的某一个字段值循环添加到combobox中,
我是用adoquery组件来连接数据库的,我编写的代码是:
adoquery1.Close ;
adoquery1.SQL.Clear ;
adoquery1.SQL.Add('select 用户编号 from 用户清单');
adoquery1.Open;
if not adoquery1.Eof then
for i:=0 to adoquery1.recordcount do
begin
combobox1.Items.Add(adoquery1.['用户编号']);
end;
但是添加的是第一个字段值,没有循环添加该字段的所有字段值。
请大家指点?

解决方案 »

  1.   

    combobox1.items[i].Add(Adoquery1.['用户编号 ']);
      

  2.   

    adoquery1.Close ;
    adoquery1.SQL.Clear ;
    adoquery1.SQL.Add('select 用户编号 from 用户清单');
    adoquery1.Open;
    adoquery1.first;
    while not adoquery1.Eof do
    begin
    combobox1.Items.Add(adoquery1.fieldvalues['用户编号']);
    adoquery1.next;
    end;
      

  3.   

    adoquery1.Close ;
    adoquery1.SQL.Clear ;
    adoquery1.SQL.Add('select distinct 用户编号 from 用户清单');
    adoquery1.Open;
    if not adoquery1.isempty then
    while not adoquery1.Eof then
    begin
    combobox1.Items.Add(adoquery1.fieldbyname('用户编号').asstring);
    adoquery1.next;
    end; 
    adoquery1.close;
      

  4.   

    adoquery1.Close ;
    adoquery1.SQL.Clear ;
    adoquery1.SQL.Add('select 用户编号 from 用户清单');
    adoquery1.Open;
    if not adoquery1.Eof then
    for i:=0 to adoquery1.recordcount do
    begin
    combobox1.Items.Add(adoquery1.['用户编号']);
    adoquery1.next
    end;
      

  5.   

    加个adoquery1.next,并且你哪个for循环应该终止于adoquery1.recordcount-1.for i:=0 to adoquery1.recordcount-1 do
    begin
    combobox1.Items.Add(adoquery1.['用户编号']);
    adoquery1.next;
    end;
      

  6.   

    可以写个通用的过程向COMBOBOX中添加项目就可以了。
    按楼上大哥的说法就可以了。
      

  7.   

    adoquery1.Close ;
    adoquery1.SQL.Clear ;
    adoquery1.SQL.Add('select distinct 用户编号 from 用户清单');
    adoquery1.Open;
    if not adoquery1.isempty then
    while not adoquery1.Eof then
    begin
    combobox1.Items.Add(adoquery1.fieldbyname('用户编号').asstring);
    adoquery1.next;
    end; 
    adoquery1.close;
      

  8.   

    正确答案来了:
    whith Adoquery1 do
    begin
      Close ;
      SQL.Clear ;
      SQL.Add('select 用户编号 from 用户清单');
      Open;
      Clear;
      First;
      while not adoquery1.Eof then
      begin
       Items.Add(FieldByName('用户编号').asstring);
       Next;
      end;
    end;
      

  9.   

    http://www.somade.com/是个很专业的技术社区,去那里找找吧,或许有你要的答案~
      

  10.   

    我觉得这样写是最好的哦:
    try
    with adoquery1 do
     begin
         Close ;
         SQL.Clear ;
         SQL.Add('select 用户编号 from 用户清单');
         Open;
     end;if not adoquery1.Eof then
    for i:=0 to adoquery1.recordcount-1 do
    begin
    combobox1.Items.Add(adoquery1.['用户编号']);
    adoquery1.next
    end;
    except
    end;