zoukankan      html  css  js  c++  java
  • Delphi中accesss实现树形结构查询系统

    主要是要读取数据库的信息,而delphi界面是一个树形结构。

    例如有一个Ascess数据库:示例.MDB,内有一张表:“国家”,表的内容如下:

    编号        名称
      01                 中国   
      0101             吉林省   
      010101         长春市   
      010102         吉林市   
      0102             江苏省   
      010201         南京市   
      010202         常州市   
      02                 美国   
      0201             密歇根州   
      020101         底特律市   
      0202             华盛顿州   
      020201         温哥华市   
      020202         西雅图市   
      03                 澳大利亚

    在 TreeView 中显示结构

    1.  新建一个Delphi工程

    2.  在主窗体上,放一个TTreeView控件、一个TADoDataSet控件和一个按钮,

        设置ADoDataSet1的ConnectionString属性为:Provider=Microsoft.Jet.OLEDB.4.0;Data Source=示例.mdb;Persist Security Info=False

    3.  添加按钮响应代码:

    procedure TForm1.Button1Click(Sender: TObject);
    const
      ID_DEPT 2;
    var
      nLevel: Integer;
      pNodes: array[0..1023] of TTreeNode;
      lpID, lpName: string;
    begin
      ADODataSet1.Close;
      ADODataSet1.CommandText :'SELECT * FROM [国家] ORDER BY [编号]';
      ADODataSet1.Open;
      pNodes[0] := nil;
      TreeView1.Items.Clear;
      with ADODataSet1.Recordset do
        while not Eof do
        begin
          lpID := Fields['编号'].Value;
          lpName := Fields['名称'].Value;
          nLevel := Length(lpID) div ID_DEPT;
          pNodes[nLevel] := TreeView1.Items.AddChild(pNodes[nLevel - 1], lpName);
          MoveNext;
        end;
    end;
  • 相关阅读:
    co coa ch ina
    提高英语听力最好的学习方法
    http://www.funnygames.us/search/?s=balance
    flash
    https://github.com/search?l=ObjectiveC&p=2&q=cocos&ref=searchbar&type=Repositories
    game.m https://github.com/kayrules/Cocos2dEndlessPlatformerGame
    2013年下半年学习计划
    Javascript判断数据类型
    vue组件自定义属性命名
    BZOJ 1018 线段树维护连通性
  • 原文地址:https://www.cnblogs.com/jijm123/p/13179965.html
Copyright © 2011-2022 走看看