Click here to Skip to main content
Click here to Skip to main content
Go to top

DBTree

, 16 Nov 2007
Rate this:
Please Sign up or sign in to vote.
A DB Base Tree that load it's nodes from a table
Screenshot - LoadTree.jpg

Introduction

This is a simple code to show how we can load a tree nodes from a table records.

How we use this code

At first step we must create a DataBase and name it "dbTree".
Then we must run this script to create table that reserve our tree nodes. We name this table "tPOI":

//
// 
USE [dbTree]
GO
/****** Object:  Table [dbo].[tPOI]    Script Date: 11/17/2007 09:32:01 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE TABLE [dbo].[tPOI](
 [NodeID] [numeric](18, 0) IDENTITY(1,1) NOT NULL,
 [ParentID] [numeric](18, 0) NULL,
 [NodeName] [nchar](10) COLLATE Arabic_CI_AS NULL,
 [InUse] <bit> NULL CONSTRAINT [DF_tPOI_InUse]  DEFAULT ((1)),
CONSTRAINT [PK_tPOI] PRIMARY KEY CLUSTERED 
(
 [NodeID] ASC
)WITH (PAD_INDEX  = OFF, STATISTICS_NORECOMPUTE  = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS  = ON, ALLOW_PAGE_LOCKS  = ON) ON [PRIMARY]
) ON [PRIMARY]
//

And finally load this records to "tPOI".

//
NodeID  ParentID          NodeName                InUse
1         0             RootNode1        True
2         1             Child1            True
3         1             Child2            True
4         1             Child3            True
5         2             Child1_1        True
6         2             Child1_2        True
7         0             RootNode2        True
//

How it works?

Our strategy to load nodes is simple: RootNodes don't have ParentNode so we set their ParentNode Field to Zero ("0") and every child node has a parent node that help us to attach this node to its parent.
Is Simple, isn't?

Now we go to code section:
There is just one function that load records to tree, "treeLoader()".

License

This article has no explicit license attached to it but may contain usage terms in the article text or the download files themselves. If in doubt please contact the author via the discussion board below.

A list of licenses authors might use can be found here

Share

About the Author

MH2538
Web Developer
Iran (Islamic Republic Of) Iran (Islamic Republic Of)
I was born and live in Tehran, Iran.
I start programming with Visual C++ 5.0 on 1997
and then jump to Delphi for 4 years and finally i'm here with C# and VB.net

Comments and Discussions

 
GeneralGood concept but needs improvement PinmemberDouglas R. Keesler17-Nov-07 14:50 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.

| Advertise | Privacy | Mobile
Web01 | 2.8.140916.1 | Last Updated 17 Nov 2007
Article Copyright 2007 by MH2538
Everything else Copyright © CodeProject, 1999-2014
Terms of Service
Layout: fixed | fluid