procedure TForm1.FormCreate(Sender: TObject);
var
  Nod1,Nod2,Nod3:TTreeNode;
  Query1:TAdoquery;
begin
  Treeview1.Items.Clear;
  Nod1:=Treeview1.Items.Add(Nil,'用户信息');
  Query1:=TADOQuery.Create(self);
  Query1.Connection :=ADOConnection1;
  Query1.SQL.Clear ;
  query1.SQL.Add('select name from txle');
  query1.Open;
  while not query1.Eof do
  begin
    Nod2:=Treeview1.Items.AddChild(nod1,adoquery2.fieldbyname('type').Asstring);
    adoQuery2.SQL.Text :='select name from txle where type=:A';
    adoQuery2.Parameters.ParamByName('A').Value :=nod2.Text ;
    adoQuery2.Open ;
    while not adoQuery2.Eof do
    begin
      nod3 :=TreeView1.Items.AddChild(nod2,adoQuery2.fieldByName('name').AsString );
      adoquery2.Next;
  end;
  query1.Next;
end;
end; 
---------------------------------------------------
Project Project1.exe raised exception class EDatabaseError with message 'ADOQuery2: field' type ' not found'. Process stopped. Use Step or Run to continue.
------------------------------------------------------
我写的这段代码,出现了上面的错,为什么,
  我的表里明明有type字段!

解决方案 »

  1.   

    最好不要使用保留字作为名字
    再就是,在OnShow中看看如何http://lysoft.7u7.net
      

  2.   

    .......
    .......  
    Query1.SQL.Clear ;
      query1.SQL.Add('select name from txle');
      query1.Open;
      while not query1.Eof do
      begin
        Nod2:=Treeview1.Items.AddChild(nod1,adoquery2.fieldbyname('type').Asstring);
    上句的adoquery2从哪来,在引用前你根本就没打开该数据集,怎么会找到呢
      

  3.   

    楼主先show一下:adoQuery2.fieldByName('name').AsString 吧。
    好象是你的adoQuery2未打开吧