如何把combobox的items用数据库里的对应键付值
其实很简单,就是一个检验登陆的程序,在数据库里有个login_user的表,里边有用户名和密码,在程序启动的时候有个combox可以根据表去选择用户名,校验密码

解决方案 »

  1.   

    先select 用户名,密码 from login_user
    然后combobox.items.add(adoquery.filebyname('用户名').asstring)
    就可以了
      

  2.   

    一般只有用戶名不多的情況, 才會用你這種 combobox 選擇的方式, 
    那麼, 如果不多的話,
    打開一個dataSet, 然後, 從頭到尾 依次加到 combobox.items 應該就可吧!
      

  3.   

    with adoquery1 do
    begin
      Close;
      Sql.Clear();
      Sql.Add('select * from tabel1');
      Open;
      combobox1.items.clear;
      First;
      while not eof do
      begin
        combobox1.items.add(FieldbyName('name').asstring);
        next;
      end;
    end;
      

  4.   

    tmpQuery := TADOQuery.Create(self);
        tmpQuery.Connection := FADOCon;    tmpQuery.Close;
        tmpQuery.SQL.Clear;
        tmpQuery.SQL.Add('SELECT DISTINCT 用户名 FROM login_user;');
        tmpQuery.Open;    ComboBox1.Items.Clear;
        tmpQuery.First;
        while not tmpQuery.Eof do
        begin
          if length(trim(tmpQuery.Fields[0].AsString)) > 0 then
            ComboBox1.Items.Add(tmpQuery.Fields[0].AsString);
          tmpQuery.Next;
        end;
        tmpQuery.Free;
      

  5.   

    combobox1.text:=adoquery1.fieldvalues['字段'];
    adoquery1.next;
      

  6.   

    with adoquery1 do
    begin
      Close;
      Sql.Clear();
      Sql.Add('select name from tabel1');
      Open;
      combobox1.items.clear;
      First;
      while not eof do
      begin
        combobox1.items.add(FieldbyName('name').asstring);
        next;
      end;
    end;