如何从数据库(sql server)中读一组数据出来(人名),放到ComboBox中?

解决方案 »

  1.   

    bcb下的代码,你改一改吧void __fastcall TForm_newmember::setcombox(AnsiString tablename, AnsiString fieldname, TComboBox *combox)
    {
          AnsiString name;
          combox->Items->Clear();
          this->ADOQuery1->Close();
          this->ADOQuery1->SQL->Clear();
          this->ADOQuery1->SQL->Add("select * from " + tablename);
          this->ADOQuery1->Open();
          while(!this->ADOQuery1->Eof)
          {
              name=this->ADOQuery1->FieldByName(fieldname)->AsString.Trim();
              combox->Items->Add(name);
              this->ADOQuery1->Next();
          }}
      

  2.   

    汗,看不懂-_-!!另外,如何用ADOConnection连到SQL上去?
      

  3.   

    procedore Tform.button1click(sender:object)
      begin
        with ADOQuery1 do
         begin
           close;
           SQL.clear;
           SQL.add('select * from table')
           open;
           combobox1.item.clear;
           while not eof do
            begin
              if combobox1.items.indexof(findfield('字段').asstring)>0 then  //去重复的 
              combobox1.items.add(findfield('字段').asstring);
              next;
            end;     
         end;
      end;
      

  4.   

    谢谢azsoft(Try my best),已经可以了,不过有一个问题,如果使用了
    if combobox1.items.indexof(findfield('字段').asstring)>0 then  这句,就得不到数据,只有屏蔽了才有用
      

  5.   

    ...
    if combobox1.items.indexof(findfield('字段').asstring)=0 then
    ...