怎么样能把一个数据表中的第一个字段中的所有数据全都显示在一个listbox1中呢?
如:把一个学生表student.db的第一个字段sno显示在 listbox1中

解决方案 »

  1.   

    while not table1.Eof do
        begin      listbox1.Items.Add(table1.FieldByName('sno').AsString);
          table1.Next;    end;
    table1的active属性设置为true!
      

  2.   

    Query1.clear;
    Query1.SQL.Add('Select sno from student');
    Query1.ExecSQL;
    try
      Query1.Open;
      for i:=0 to Query1.RecordCount-1 do
        ListBox1.Items.Add(FieldByName('sno').AsString);
      Query1.Close;
    except
      ...
    end;
      

  3.   

    一行一行的读取相应的字段,添加listbox1.item[i]
      

  4.   

    for i:=1 to Adoquery1.RecordCount do
       begin
          listbox1.Items.Add(ADOquery1.FieldByName('sell_num').AsString);
          ADOQuery1.Next;
       end;
      

  5.   

    with query1 do
    begin
      close;
      sql.clear;
      sql.add('select sno from student');
      open;
      first;
      while not eof do
      begin
        listbox1.item.add(fieldbyname('sno').asstring);
        next;
      end;
    end;
      

  6.   

    while not table1.Eof do
        begin      listbox1.Items.Add(table1.FieldByName('sno').AsString);
          table1.Next;    end;
      

  7.   

    var 
      i:integer
    begin
      with query1 do
      begin
        close;
        sql.clear;
        sql.add('select sno from student');
        open;
        first;
        for i:=1 to Adoquery1.RecordCount do
        begin
          listbox1.item.add(fieldbyname('sno').asstring);
          next;
        end;
      query1.close
    end;
      

  8.   

    listbox1.items.clear;//记得清空,否则越加越多
      with adoquery1 do
      begin
        close;
        sql.clear;
        sql.add(' select sno from tablename1');
        open;
        first;
        while not eof do
        begin
          listbox1.items.add(FieldByName('sno').AsString);
          next;
        end;
        close;
      end;