procedure TForm10.FormCreate(Sender: TObject); begin with dm.ADOQuery1 do begin close; sql.Clear; sql.Text:='select distinct * from edit'; open; first; while not eof do begin combobox1.Items.Add(fields[4].Value ); next; end; combobox1.ItemIndex :=0; end; 这段程序是从数据库里调用某个字段的数据,假如数据库的某个字段值是1、2、 3、2,在combox里列出来的数据也将是1、2、3、2,而我想把那个重复的2给合并了就显示1、2、3,大哥们帮我
----------------------------------------------
我是菜鸟!
在你的SQL语句中加入排序如下所示 var tmpstr:string; Sql.text:='select distinct * from edit Ader by 你要调的字段'; tmpstr:=''; while not eof do begin if Fields[4].Value<>tmpstr then Combox1.Items.Add(Fields[4].Value); tmpstr:=Fields[4].Value; next; end; 没调试,给你个参考吧!
不好意思写错了几个词。Sorry var tmpstr:string; Sql.text:='select distinct * from edit order by 你要调的字段 ASC'; tmpstr:=''; while not eof do begin if Fields[4].Value<>tmpstr then Combox1.Items.Add(Fields[4].Value); tmpstr:=Fields[4].Value; next; end; 没调试,给你个参考吧!
with dm.ADOQuery1 do begin close; sql.Clear; Sql.text:='select distinct * from edit order by ht_danwei'; tmpstr:=''; while not eof do begin if Fields[4].Value<>tmpstr then form10.ComboBox1.Items.Add(Fields[4].Value); tmpstr:=Fields[4].Value; next; end; form10.ComboBox1.ItemIndex:=0; 是这样吗?但还是不行啊!你发到我zjmetal@hotmail.com
----------------------------------------------
我是菜鸟!