Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people, just like you, are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
Solved

Shortening a TreeView logic.

Posted on 2009-04-02
3
424 Views
Last Modified: 2013-12-14
Hi I'm currently working on a TreeView with Oracle Database.
The thing is I have to connect to 2 databases in this TreeView and due to the column name and description naming differences I could'nt use the UNION function in the SQL statement.

So I used Code1 to populate the TreeView untill the 5th level and the code compile in less then 10 seconds.

After that I proceed to connecting the 2nd database and it'll be on the 6th level but when i put Code2 inside the "if (strList.Length == 5)" statement the code compile more then 2 minutes which is really unaccecptable.

I'm hoping if anyone could provide solutions to shorten the compilation time.
 Thanks in advaance.
// Code1
                    foreach (DataRow dr in ordt.Rows)
                    {
                        nodeCheck = new TreeNode();
                        nodeCheck.Name = dr[0].ToString();                        
                        strText = dr[2].ToString();
                        strDesc = dr[3].ToString();
                        strList = strText.Split('.');
                        nodeCheck.Text = strList[strList.Length - 1];
                        if (dr[1] != DBNull.Value)
                        {
                            node = treeScadaItems.Nodes.Find(dr[1].ToString(), true);
                            if (strList.Length == 5)
                                {
                                    node[0].Nodes.Add(nodeCheck);
                                }
                                else
                                { node[0].Nodes.Add(nodeCheck); }
                        }
                        else
                        {
                            treeScadaItems.Nodes.Add(nodeCheck);
                        } 
                    } 
                                    // Code2
                                    localSQL = "SELECT KEYID,PRODUCT_NAME,PRODUCT_DESC,PKEYID,PRODUCT_TYPE FROM PRODUCT_PT WHERE PKEYID LIKE '" + dr[0].ToString() + "'";
                                    OracleCommand cmdOracle1 = new OracleCommand(localSQL, localConnection);
                                    cmdOracle1.CommandType = CommandType.Text;
                                    drOracle = cmdOracle1.ExecuteReader();
                                    while (drOracle.Read())
                                    {
                                        nodeCheck = new TreeNode();
                                        nodeCheck.Name = dr[0].ToString();
                                        strText = drOracle.GetOracleString(1).ToString();
                                        nodeCheck.Text = strText.ToString();
                                        node[0].Nodes.Add(nodeCheck);
 
                                        nodeCheck.Tag = drOracle.GetOracleValue(0).ToString();
                                    }
                                    drOracle.Close();

Open in new window

0
Comment
Question by:csharp_learner
  • 2
3 Comments
 
LVL 9

Accepted Solution

by:
kprestage earned 500 total points
ID: 24061767
How many nodes does the first query add?  How about the second query?  Are you sure it is a code problem and not an issue with the Treeview loading too many nodes?  The Tree gets VERY slow when you start adding a lot of nodes to it.  
0
 
LVL 9

Assisted Solution

by:kprestage
kprestage earned 500 total points
ID: 24061803
Also, are you calling the treeview's BeginUpdate before your loop and EndUpdate after your loop?  If not, try that and see if you have some improvement.
0
 

Author Comment

by:csharp_learner
ID: 24083680
Sorry for the late reply,

Yes your're correct there is alot of nodes the TreeView needs to load.
How can I put the BeginUpdate and EndUpdate into my code?
As I can only access to BeginEdit and BeginInvoke when i tried to access using treeview1.
0

Featured Post

Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
System.Security 2 28
Wav problem 4 28
Jquery/JSON passing value from one function to another 12 60
C# LINQ ForEach() question 6 48
Introduction This article series is supposed to shed some light on the use of IDisposable and objects that inherit from it. In essence, a more apt title for this article would be: using (IDisposable) {}. I’m just not sure how many people would ge…
The article shows the basic steps of integrating an HTML theme template into an ASP.NET MVC project
This tutorial covers a step-by-step guide to install VisualVM launcher in eclipse.
The viewer will learn how to use and create new code templates in NetBeans IDE 8.0 for Windows.

791 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question