access中的字段
  年份    月份
  2003    10
  2003    8
  2002    4
   ...    ...
怎样形成树状结构
+2003
   8
   10
+2002
   4

解决方案 »

  1.   

    我在定义的时候将表名定义为V11,年份字段定义为V1101,月份为V1102;
    代码如下;procedure TForm1.Button1Click(Sender: TObject);
    var L : Ttreenode;
        ado : Tadoquery ;
        str : string;
    begin
        with adoquery1 do
          begin
             close;
             sql.Clear;
             sql.Text := 'select V1101 from V11 guoup by V1101';
             open;
             while not eof do
              begin
                 str := fieldbyname('V1101').AsString ;
                 L :=  treeview1.Items.Add(nil,str);
                 try
                     ado := tadoquery.Create(self);
                     ado.Connection := adoconnect1;
                     with ado do
                      begin
                          sql.Text := 'select V1102 from V11 where V1101 = '+ str;
                          open;
                          while not eof do
                          begin
                              treeview1.Items.AddChild(L,fieldbyname('V1102').AsString);
                          end;
                      end;
                 finally ado.free;
                 except ado.free;
                 end;
              end;
          end;
    end;
      

  2.   

    sorry;刚才有几个小的笔误;正确的代码是下面这个;^_^procedure TForm1.Button1Click(Sender: TObject);
    var L : Ttreenode;
        ado : Tadoquery ;
        str : string;
    begin
        with adoquery1 do
          begin
             close;
             sql.Clear;
             sql.Text := 'select V1101 from V11 group by V1101';
             open;
             while not eof do
              begin
                 str := fieldbyname('V1101').AsString ;
                 L :=  treeview1.Items.Add(nil,str);
                 try
                     ado := tadoquery.Create(self);
                     ado.Connection := adoconnection1;
                     with ado do
                      begin
                          sql.Text := 'select V1102 from V11 where V1101 = '+ str;
                          open;
                          while not eof do
                          begin
                              treeview1.Items.AddChild(L,fieldbyname('V1102').AsString);
                              next;
                          end;
                      end;
                 ado.free;
                 except ado.free;
                 end;
              next;
              end;
          end;
    end;