Solved

How to put this inisde a child node?

Posted on 2009-04-01
16
180 Views
Last Modified: 2012-05-06
Hi, my current TreeView looks something like this...
-X01
   -store
      -brand
         -product
            -101
            -101.abc
            -101.xyz
            -102
            -102.abc
            -102.xyz
101.abc,101.xyz,102.abc and 102.xyz is read from the 2nd localSQL statement.
But what I wanted was for the data from the new database to be under the respective node...
            -101
               -101.abc
               -101.xyz
            +102

The following is my code the // part is the part where i connect to the new database and add it to the node.
Thanks for any help in advance.
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 = treeview1.Nodes.Find(dr[1].ToString(), true);

                            if (strList.Length == 5)

                                {

                                    nodeCheck.Text = nodeCheck.Text;

                                    node[0].Nodes.Add(nodeCheck);
 

                                    //localSQL = "SELECT * 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();

                                }

                                else

                                { node[0].Nodes.Add(nodeCheck); }

                        }

                        else

                        {

                            treeview1.Nodes.Add(nodeCheck);

                        } 

                    }

Open in new window

0
Comment
Question by:csharp_learner
  • 8
  • 5
  • 3
16 Comments
 
LVL 40

Expert Comment

by:mrjoltcola
ID: 24045933
If you are using 2 Oracle databases, you can just setup a database link and connect directly to one database only. Then you refer to the table as table@remote

Not sure if that helps, as I don't quite understand what you are doing. Let me know if I can help more or if you want syntax for creating the database link. Your DBA has to do it, or grant you "create database link" privilege.


0
 

Author Comment

by:csharp_learner
ID: 24045980
Do you mean the Union function in the SQL statement?
I'm open to hearing u're database link option,since my current code is giving me some Context error due to the 2nd connection.
ps:both databases have the same column PKEYID.
0
 
LVL 40

Expert Comment

by:mrjoltcola
ID: 24045999
Sample uses ORA1 and ORA2, change to match your local and remote.

ORA2 must be in the TNSNAMES.ORA file of the ORA1 database

Verify from ORA1 server by doing:  tnsping ORA2

Then, either as DBA create a public database link, or have your DBA grant "create database link to <user>"

Sample from SQLPlus/etc. to create a link to the SCOTT user on the ORA2 database

SQL> create database link ORA2 connect to scott identified by tiger using 'ORA2';

SQL> select * from EMP@ORA2;
0
 
LVL 40

Expert Comment

by:mrjoltcola
ID: 24046007
And you can refer to tables on both databases in 1 query. Say I have EMP table on local database and remote ORA2.

select a.* from EMP a, EMP@ORA2 b
where a.ID = b.id
0
 

Author Comment

by:csharp_learner
ID: 24046073
I've tried to connect using the SQL Editor in Oracle but seems my statement is wrong.
This is my 1st SQL query:
SELECT KEYID,PKEYID, PRODUCT_NAME,PRODUCT_DESC FROM PRODUCT_NODE START WITH PKEYID IS NULL CONNECT BY PRIOR KEYID = PKEYID ORDER BY PRODUCT_NAME
and this is my 2nd SQL query:
SELECT KEYID,PRODUCT_NAME,PRODUCT_DESC,PKEYID,PRODUCT_TYPE FROM PRODUCT_PT
0
 
LVL 6

Expert Comment

by:HarryNS
ID: 24047117
Can you give me the result of the above mentioned 2 queries?
0
 

Author Comment

by:csharp_learner
ID: 24047352
Thanks for offering your help again Harry.
Actually you help solve the 1st part of the code
http://www.experts-exchange.com/Programming/Languages/C_Sharp/Q_24258181.html

Now i'm trying to connect to a new databse using dr[0].ToString()  where it'll grab the KEYID from the previous databse to the current databse KEYID where there will be a few items under it.

Example: after reading 101 which is the last child node in the old databse the new connection of database will grab 101's KEYID '41' then under the new database there will be a list of items under the same KEYID column
(1st databse)
KEYID     PKEYID     PRODUCT_NAME
41           31             X01.Alpha.metal.cabin.101
(2nd databse)
KEYID     PKEYID     PRODUCT_NAME
201          41             abc
202          41             xyz
0
 

Author Comment

by:csharp_learner
ID: 24047368
sorry my mistake the 2nd database table is like this
(2nd databse)
KEYID     KEYID     PRODUCT_NAME
201          41             abc
202          41             xyz
0
Highfive Gives IT Their Time Back

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

 
LVL 6

Expert Comment

by:HarryNS
ID: 24047531
SELECT KEYID, PKEYID, PRODUCT_NAME, PRODUCT_DESC
FROM
PRODUCT_NODE START
WITH PKEYID IS NULL CONNECT BY PRIOR KEYID = PKEYID ORDER BY PRODUCT_NAME

UNION ALL
SELECT KEYID, PKEYID, PRODUCT_NAME, PRODUCT_DESC, PRODUCT_TYPE
FROM PRODUCT_PT

Can you make the result as One. This will give you good application performance and easy to use as well.
0
 

Author Comment

by:csharp_learner
ID: 24047642
I tried
SELECT KEYID,PKEYID, PRODUCT_NAME,PRODUCT_DESC FROM PRODUCT_NODE START WITH PKEYID IS NULL CONNECT BY PRIOR KEYID = PKEYID ORDER BY PRODUCT_NAME UNION ALL SELECT KEYID, PKEYID, PRODUCT_NAME, PRODUCT_DESC, PRODUCT_TYPE FROM PRODUCT_PT
but i got an error SQL command not properly ended @ "union"
0
 
LVL 6

Accepted Solution

by:
HarryNS earned 500 total points
ID: 24047752
SELECT KEYID, PKEYID, PRODUCT_NAME, PRODUCT_DESC
FROM
PRODUCT_NODE START
WITH PKEYID IS NULL CONNECT BY PRIOR KEYID = PKEYID
UNION ALL
SELECT KEYID, PKEYID, PRODUCT_NAME, PRODUCT_DESC, PRODUCT_TYPE
FROM PRODUCT_PT

ORDER BY PRODUCT_NAME
0
 

Author Comment

by:csharp_learner
ID: 24047811
When i place the ORDER BY PRODUCT_NAME at the end it prompt "query block has incorrect number of result columns"
I tried to simplify every thing by SELECT * FROM PRODUCT_NODE START WITH PKEYID IS NULL CONNECT BY PRIOR KEYID = PKEYID UNION ALL SELECT * FROM PRODUCT_PT but ehe same "query block..."error came out.
0
 
LVL 6

Expert Comment

by:HarryNS
ID: 24047845
Include Product Type in your first query or remove it from the second query. When you use UNION, you need to produce similar kind of rows.
0
 

Author Comment

by:csharp_learner
ID: 24047986
Sorry i've read wrongly the column name of the 2nd database table.

SELECT KEYID,PKEYID, PRODUCT_NAME,PRODUCT_DESC FROM PRODUCT_NODE
UNION ALL
SELECT KEYID, PKEYID, PRODUCT_DT_NAME, PRODUCT_DT_DESC, PRODUCT_TYPE FROM PRODUCT_PT

Since only the KEYID and PKEYID columns are the same does it mean i can't use this UNION function?
0
 
LVL 6

Expert Comment

by:HarryNS
ID: 24048228
No, No. of columns should be same. First query is having Key ID, PKey ID, Name and Desc. Second query is having Key ID, PKey ID, Name, Desc and TYPE. Type is extra in second query. If you remove Product_type in 2nd query this will work fine. or include Type in first query also.
0
 

Author Comment

by:csharp_learner
ID: 24055994
Sorry for the late reply but in my 2nd query it's named PRODUCT_DT_NAME and PRODUCT_DT_NAME, in the 1st query it's named PRODUCT_NAME and PRODUCT_DESC.
0

Featured Post

How to improve team productivity

Quip adds documents, spreadsheets, and tasklists to your Slack experience
- Elevate ideas to Quip docs
- Share Quip docs in Slack
- Get notified of changes to your docs
- Available on iOS/Android/Desktop/Web
- Online/Offline

Join & Write a Comment

It was really hard time for me to get the understanding of Delegates in C#. I went through many websites and articles but I found them very clumsy. After going through those sites, I noted down the points in a easy way so here I am sharing that unde…
Real-time is more about the business, not the technology. In day-to-day life, to make real-time decisions like buying or investing, business needs the latest information(e.g. Gold Rate/Stock Rate). Unlike traditional days, you need not wait for a fe…
Video by: Steve
Using examples as well as descriptions, step through each of the common simple join types, explaining differences in syntax, differences in expected outputs and showing how the queries run along with the actual outputs based upon a simple set of dem…
This video shows how to copy an entire tablespace from one database to another database using Transportable Tablespace functionality.

743 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

Need Help in Real-Time?

Connect with top rated Experts

15 Experts available now in Live!

Get 1:1 Help Now