如何把从数据库表中查询到的结果,赋值到comboBox框中?
  具体是:
    用sql语句从数据库表中查询到“编号”(整型)字段值,
  如何把它赋值给comboBox,运行程序时,可以从中选择一个编号值。

解决方案 »

  1.   

    先到到数据集中DataSet
    while not dataset.eof
      combobox.add dataset.fieldbyname('编号').asstring;
      

  2.   

    设表名: table1procedure GetBH;
    var
      ads1: TADODataSet;
      scmd: string;
      adc: TADOConnection;
    begin
      ads1.conn := adc;
      1,连接到数据库(激活adc)
      2,打开数据集:
        scmd := 'select 编号 from 表1';
        ads1.Open;
      3,挂到ComboBox中:
        with ads1 do
        begin
          first;
          while not eof do
          begin
            ComboBox1.Item.add(FieldByName('编号').asString)
            Next;
          end;
        end;
    end;
      

  3.   

    with ADOQuery do
    begin
      Close;
      SQL.Clear;
      SQL.Add('select * from tablename');
      Open;
      First;
      ComBox1.Items.Clear;
      while not Eof do
      begin
        ComBox1.Items.Add(FieldByName('编号').asString);
        Next;
      end;
    end;
      

  4.   


    begin
      ADOQuery.Close;
      ADOQuery.SQL.Clear;
      ADOQuery.SQL.Add('select * from tablename');
      ADOQuery.Open;
      ADOQuery.First;
      ComBox1.Items.Clear;
      while not ADOQuery.Eof do
      begin
        ComBox1.Items.Add(FieldByName('编号').asString);
        ADOQuery.Next;
      end;
    end;
      

  5.   

    谢谢大家帮忙,我已经试过了,这个赋值解决了,下面我还需要在程序运行的过程中,根据comobox框中选定的编号在表中选出与此编号对应的“名称”的字段值,之后赋值给一个edit框,
       具体:
          表中定义的编号为int型,名称为char型,把combobox框中的值取出来,作为sql
      语句中查询依据,中间的取值过程,类型转换过程,查询赋值过程各位能帮我写一下吗?
      谢谢大家的支持与帮助!