苦
苦命的人
Unregistered / Unconfirmed
GUEST, unregistred user!
procedure TForm1.FormActivate(Sender: TObject);
var
sql,sql1:string;
tempi: integer;
begin
sql:='select * from wuzibianma_dalei';
adoquery1.close;
adoquery1.sql.clear;
adoquery1.sql.add(sql);
adoquery1.open;
while not adoquery1.eof do
begin
//加入大类
tempi := tv.Items.AddChild(tv.topitem,adoquery1.fieldbyname('物资大类').asstring).AbsoluteIndex;
sql1:='select * from wuzibianma_zhonglei where 大类代号=:sf';
adoquery2.close;
adoquery2.sql.clear;
adoquery2.sql.add(sql1);
adoquery2.Parameters.ParamValues['sf']:=adoquery1.fieldbyname('大类代号').asstring;
adoquery2.open;
while not adoquery2.eof do
begin
//加入中类
tv.Items.AddChild(tv.Items.Item[tempi],adoquery2.fieldbyname('物资中类').asstring);
adoquery2.next;
end;
adoquery1.next;
end;
end;
以上的代码,我把数据库里的物资大类全部加到treeview里去了,又把物资中类加到相应的大类里去了,好用,但是我下面的代码是
把物资小类加到相应的物资中类里去,怎么不好使,结果物资小类都加到物资大类去了,请高手挑错!!
procedure TForm1.FormActivate(Sender: TObject);
var
sql,sql1:string;
tempi: integer;
begin
sql:='select * from wuzibianma_dalei';
adoquery1.close;
adoquery1.sql.clear;
adoquery1.sql.add(sql);
adoquery1.open;
while not adoquery1.eof do
begin
//加入大类
tempi := tv.Items.AddChild(tv.topitem,adoquery1.fieldbyname('物资大类').asstring).AbsoluteIndex;
sql1:='select * from wuzibianma_zhonglei where 大类代号=:sf';
adoquery2.close;
adoquery2.sql.clear;
adoquery2.sql.add(sql1);
adoquery2.Parameters.ParamValues['sf']:=adoquery1.fieldbyname('大类代号').asstring;
adoquery2.open;
while not adoquery2.eof do
begin
//加入中类
tv.Items.AddChild(tv.Items.Item[tempi],adoquery2.fieldbyname('物资中类').asstring);
sql1:='select * from wuzibianma_xiaolei where 中类代号=:sf';
adoquery3.close;
adoquery3.sql.clear;
adoquery3.sql.add(sql1);
adoquery3.Parameters.ParamValues['sf']:=adoquery2.fieldbyname('中类代号').asstring;
adoquery3.open;
while not adoquery3.eof do
begin
//加入小类
//应该是在这里出的毛病,就是那个tempi
tv.Items.AddChild(tv.Items.Item[tempi],adoquery3.fieldbyname('物资小类').asstring);
adoquery3.Next;
end;
adoquery2.next;
end;
adoquery1.next;
end;
end;
var
sql,sql1:string;
tempi: integer;
begin
sql:='select * from wuzibianma_dalei';
adoquery1.close;
adoquery1.sql.clear;
adoquery1.sql.add(sql);
adoquery1.open;
while not adoquery1.eof do
begin
//加入大类
tempi := tv.Items.AddChild(tv.topitem,adoquery1.fieldbyname('物资大类').asstring).AbsoluteIndex;
sql1:='select * from wuzibianma_zhonglei where 大类代号=:sf';
adoquery2.close;
adoquery2.sql.clear;
adoquery2.sql.add(sql1);
adoquery2.Parameters.ParamValues['sf']:=adoquery1.fieldbyname('大类代号').asstring;
adoquery2.open;
while not adoquery2.eof do
begin
//加入中类
tv.Items.AddChild(tv.Items.Item[tempi],adoquery2.fieldbyname('物资中类').asstring);
adoquery2.next;
end;
adoquery1.next;
end;
end;
以上的代码,我把数据库里的物资大类全部加到treeview里去了,又把物资中类加到相应的大类里去了,好用,但是我下面的代码是
把物资小类加到相应的物资中类里去,怎么不好使,结果物资小类都加到物资大类去了,请高手挑错!!
procedure TForm1.FormActivate(Sender: TObject);
var
sql,sql1:string;
tempi: integer;
begin
sql:='select * from wuzibianma_dalei';
adoquery1.close;
adoquery1.sql.clear;
adoquery1.sql.add(sql);
adoquery1.open;
while not adoquery1.eof do
begin
//加入大类
tempi := tv.Items.AddChild(tv.topitem,adoquery1.fieldbyname('物资大类').asstring).AbsoluteIndex;
sql1:='select * from wuzibianma_zhonglei where 大类代号=:sf';
adoquery2.close;
adoquery2.sql.clear;
adoquery2.sql.add(sql1);
adoquery2.Parameters.ParamValues['sf']:=adoquery1.fieldbyname('大类代号').asstring;
adoquery2.open;
while not adoquery2.eof do
begin
//加入中类
tv.Items.AddChild(tv.Items.Item[tempi],adoquery2.fieldbyname('物资中类').asstring);
sql1:='select * from wuzibianma_xiaolei where 中类代号=:sf';
adoquery3.close;
adoquery3.sql.clear;
adoquery3.sql.add(sql1);
adoquery3.Parameters.ParamValues['sf']:=adoquery2.fieldbyname('中类代号').asstring;
adoquery3.open;
while not adoquery3.eof do
begin
//加入小类
//应该是在这里出的毛病,就是那个tempi
tv.Items.AddChild(tv.Items.Item[tempi],adoquery3.fieldbyname('物资小类').asstring);
adoquery3.Next;
end;
adoquery2.next;
end;
adoquery1.next;
end;
end;