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)