主题:使用ADOQuery多次查询数据库的问题请教?
procedure TForm1.Button1Click(Sender: TObject);
begin
with ADOQuery1 do //查询第0级产品
begin
SQL.Clear;
sqlstr1:= 'SELECT * FROM classi where (FID=0)';
SQL.Add(sqlstr1);
Open;
i:=ADOQuery1.RecordCount;
for k:=1 to 2 do
begin
fname := fieldbyname('name').AsString; //记录根产品的名称
listbox1.Items.Add(fname);
tn:=TreeView1.Items.Add(nil,fname);
with ADOQuery2 do //依据第0级来查询第1级产品
begin
SQL.Clear;
sqlstr2:= 'SELECT b.NAME FROM classi a INNER JOIN classi b ON a.ID = b.FID WHERE a.NAME = '+''''+trim(fname)+'''';
Edit1.Text:=sqlstr2;
SQL.Add(sqlstr2);
Open;
m:=ADOQuery2.RecordCount;
form1.Caption:=inttostr(m);
for n:=1 to m do
begin
treeview1.items.addchild(tn,fieldbyname('name').AsString);
next
end;
ADOQuery2.Close;
end;
next
end;
end;
ADOQuery1.Close;
end;
请问仁兄:
我是不是数据库中有多少级产品就需要加多少个ADOQuery和DataSource。象这里有两级就要用两个ADOQuery和DataSource,如果有三级就要用三个ADOQuery和DataSource?
begin
with ADOQuery1 do //查询第0级产品
begin
SQL.Clear;
sqlstr1:= 'SELECT * FROM classi where (FID=0)';
SQL.Add(sqlstr1);
Open;
i:=ADOQuery1.RecordCount;
for k:=1 to 2 do
begin
fname := fieldbyname('name').AsString; //记录根产品的名称
listbox1.Items.Add(fname);
tn:=TreeView1.Items.Add(nil,fname);
with ADOQuery2 do //依据第0级来查询第1级产品
begin
SQL.Clear;
sqlstr2:= 'SELECT b.NAME FROM classi a INNER JOIN classi b ON a.ID = b.FID WHERE a.NAME = '+''''+trim(fname)+'''';
Edit1.Text:=sqlstr2;
SQL.Add(sqlstr2);
Open;
m:=ADOQuery2.RecordCount;
form1.Caption:=inttostr(m);
for n:=1 to m do
begin
treeview1.items.addchild(tn,fieldbyname('name').AsString);
next
end;
ADOQuery2.Close;
end;
next
end;
end;
ADOQuery1.Close;
end;
请问仁兄:
我是不是数据库中有多少级产品就需要加多少个ADOQuery和DataSource。象这里有两级就要用两个ADOQuery和DataSource,如果有三级就要用三个ADOQuery和DataSource?