Read the database recursively (*. MDB) Spanning tree node (TreeNode)

Source: Internet
Author: User

Load database record spanning tree node (TreeNode), only more than 1500 records will be used more than 4 minutes, is too slow, after thinking, reduce some unnecessary query and assignment, the speed is more obvious, perhaps the machine is older, the end result is not ideal, of course, this is too bad with their own technology.


There are more than 1500 records in the database, using recursive method to add all the records once to TreeNode, the first time to load more than 4 minutes, 3 minutes after the modification, again modified is 1 minute. Project Operating Environment: Single core CPU,2GB DDR2 memory, Win7 x86 flagship edition, C # Express,.Net4,access (*.MDB) database.

Original code:
Recursively adding child nodes
Publicstatic void Addtreenode(TreeNode node,String GUID)
{
Node.Name=Guid;
DataTable table=Publictools.Accesshelper.Executedatatable("SELECT * from familytree where p_guid = @P_GUID and Generation > 1", NewOleDbParameter("@P_GUID",Node.Name));
foreach (DataRow rowinchTable.Rows)
{
TreeNode N= NewTreeNode();
N.Name=Row["M_guid"].Tostring();
N.Text=Row["Nametext"].Tostring();
N.Tag=Row["Code"].Tostring();
Node.Nodes.Add(N);
Addtreenode(N,N.Name);
}
}

First modification: Reduce an extra parameter, comment out the TreeNode Tag property assignment
Recursively adding child nodes
Publicstatic void Addtreenode(TreeNode node)
{
Node. Name = GUID;
DataTable table=Publictools.Accesshelper.Executedatatable("SELECT * from familytree where p_guid = @P_GUID and Generation > 1", NewOleDbParameter("@P_GUID",Node.Name));
foreach (DataRow rowinchTable.Rows)
{
TreeNode N= NewTreeNode();
N.Name=Row["M_guid"].Tostring();
N.Text=Row["Nametext"].Tostring();
N.tag = row["Code"]. ToString ();
Node.Nodes.Add(N);
Addtreenode(N);
}
}


Second modification: The column returned by the query statement is owned by all (*) to use two columns instead (M_guid,Nametext)
Recursively adding child nodes
Publicstatic void Addtreenode(TreeNode node)
{
Node. Name = GUID;
DataTable table=Publictools.Accesshelper.Executedatatable("Select M_guid,nametext from familytree where p_guid = @P_GUID and Generation > 1", NewOleDbParameter("@P_GUID",Node.Name));
foreach (DataRow rowinchTable.Rows)
{
TreeNode N= NewTreeNode();
N.Name=Row["M_guid"].Tostring();
N.Text=Row["Nametext"].Tostring();
N.tag = row["Code"]. ToString ();
Node.Nodes.Add(N);
Addtreenode(N);
}
}

Read the database recursively (*. MDB) Spanning tree node (TreeNode)

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.