一条??select distinct nr from table1 where xm="性别";
然后用循环加进 combobox(cxb);

解决方案 »

  1.   

    对不起,我没说清楚。我的意思是:只进行一次sql查询和循环赋值,就可以同时给两个combobox赋值。有没有这样的sql语句?
      

  2.   

    如果真的,那就是:select * from table1     了。
    然后从循环加入combobox,如果已经加入相同的就不加咯
      

  3.   

    先把需要的字段取到一个数据集里,再进行赋值.
    with Query1 do
    begin
      SQL.Clear;
      SQL.Add('select distinct xm,nr from table where ...');
      Open;
    end;
    while (not Query1.Eof) do
    begin
      ComboBox1.Text := Query1.FieldByName('xm').AsString;
      ComboBox2.Text := Query1.FieldByName('nr').AsString;
      Query1.Next;
    end;
      
      

  4.   

    sorry,应该是:
    with Query1 do
    begin
      SQL.Clear;
      SQL.Add('select distinct xm,nr from table where ...');
      Open;
    end;
    while (not Query1.Eof) do
    begin
      Close;
      ComboBox1.Text := Query1.FieldByName('xm').AsString;
      ComboBox2.Text := Query1.FieldByName('nr').AsString;
      Query1.Next;
    end;
      
      

  5.   

    对不起,又加错了,把第二个begin后面的close移到前一个begin后面!
    哎,眼睛花了
      

  6.   

    with Query1 do
    begin
      close ;
      SQL.Clear;
      SQL.Add('select distinct xm,nr from table where ...');
      Open;
    end;
    while (not Query1.Eof) do
    begin
      ComboBox1.items.add(Query1.FieldByName('xm').AsString);
      ComboBox2.items.add(Query1.FieldByName('nr').AsString);
      Query1.Next;
    end;
      ComboBox1.itemindex := 0 ;
      ComboBox2.itemindex := 0 ;
      
      

  7.   

    是这样的:在我的form上有30多个combobox,有些combobox用来让user挑选性别,有些combobox用来让user挑选部门,有些combobox用来让user挑选学历……而且在另一个form中,这些选项的内容是可以定制的。我可以为每个选项建一个table,但是太多了,就干脆建在一个table中了。现在的问题是:我可以重复30多次用sql为每一个combobox选出在table中相应的内容,可是这样就太笨了。我相信sql语言的力量,应该可以只用一次sql查询,使同一字段不同的内容查询成不同的字段不同的内容。或者可不可以在combobox中设置类似于"filter"的属性,如:
    cxb.filter:='xm=性别'; (请不要笑我)