在delphi中如何用combobox实现分级读取数据?急急急
procedureTForm3.FormCreate(Sender:TObject);vari:integer;beginquery1.Open;fori:=0toque...
procedure TForm3.FormCreate(Sender: TObject);
var
i:integer;
begin
query1.Open;
for i:=0 to query1.Fields.Count-1 do
combobox1.items.add(query1.fields[i].fieldname);
end;
procedure TForm3.ComboBox1Change(Sender: TObject);
begin
combobox2.Items.Clear;
query1.close;
query1.SQL.Clear;
query1.SQL.Add('SELECT distinct combobox1.text from customer');
query1.Open;
while not query1.Eof do
begin
combobox2.Text:='';
combobox2.Items.Add('这里该怎么写?求高手指点指点!谢谢了!');
query1.Next;
end;
end; 展开
var
i:integer;
begin
query1.Open;
for i:=0 to query1.Fields.Count-1 do
combobox1.items.add(query1.fields[i].fieldname);
end;
procedure TForm3.ComboBox1Change(Sender: TObject);
begin
combobox2.Items.Clear;
query1.close;
query1.SQL.Clear;
query1.SQL.Add('SELECT distinct combobox1.text from customer');
query1.Open;
while not query1.Eof do
begin
combobox2.Text:='';
combobox2.Items.Add('这里该怎么写?求高手指点指点!谢谢了!');
query1.Next;
end;
end; 展开
2个回答
展开全部
无意义的代码。但是看到了还是给你修改下。
const
sql = 'select distinct %s from well_basic';
var
strlist : TStringList;
icount : integer;
begin
adoquery1.Close;
ADOQuery1.SQL.Clear;
ADOQuery1.SQL.Add('select * from well_basic ');
ADOQuery1.Open;
strlist := TStringList.Create;
ADOQuery1.GetFieldNames(strlist);
for icount := 0 to strlist.Count - 1 do
begin
ADOQuery1.Close;
ADOQuery1.SQL.Clear;
ADOQuery1.SQL.Add(Format(sql, [strlist.Strings[icount]]));
ADOQuery1.Open;
ADOQuery1.First;
while not adoquery1.Eof do
begin
ComboBox2.Items.Add(strlist.Strings[icount] + ':' + ADOQuery1.FieldByName(strlist.Strings[icount]).AsString);
adoquery1.Next;
end;
end;
strlist.Free;
end;
const
sql = 'select distinct %s from well_basic';
var
strlist : TStringList;
icount : integer;
begin
adoquery1.Close;
ADOQuery1.SQL.Clear;
ADOQuery1.SQL.Add('select * from well_basic ');
ADOQuery1.Open;
strlist := TStringList.Create;
ADOQuery1.GetFieldNames(strlist);
for icount := 0 to strlist.Count - 1 do
begin
ADOQuery1.Close;
ADOQuery1.SQL.Clear;
ADOQuery1.SQL.Add(Format(sql, [strlist.Strings[icount]]));
ADOQuery1.Open;
ADOQuery1.First;
while not adoquery1.Eof do
begin
ComboBox2.Items.Add(strlist.Strings[icount] + ':' + ADOQuery1.FieldByName(strlist.Strings[icount]).AsString);
adoquery1.Next;
end;
end;
strlist.Free;
end;
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询