Challenging PRoblem in VB.NET.

H

Hisouka

DBase = 'MYDB'
User = 'Hisouka'
Password = '1234'

HEre is my Table in SQL Server


Tablename: TABLESAMP


Field1 Field2 Field3
abs NULL PRIMARY
aaa aaa Primary 1.1
zzz bbb Primary 1.2
bbb 1234 SECONDARY
ccc zzz Secondary 1.1
ddd abs Secondary 1.2


If Record in Field2 is not exist in column Field1 then the Record in
Field3 must be a root node
If Record in Field2 is exist in Field1 then the Record in Field3 must
be a sub node of last root node


Possible list on my Tree View:


PRIMARY
Primary 1.1
Primary 1.2
SECONDARY
Secondary 1.1
Seconday 1.2


Can anyone give me possible Code? including SQL Connection..


Thanks
Aprreciation if solved..
 
R

rowe_newsgroups

Here's a website for connecting via ADO or ADO.NET using both VB and
C#. You may also dig up some info on the SQLConnection and transaction
objects, as they are optimized for SQL server.

http://support.sas.com/ctx/samples/index.jsp?sid=817

Use www.connectionstrings.com to get the appropriate connection string.

The simplist (and not the most efficient) is to pull the table into a
datareader, and start looping through it. Do your comparison in the
loop and add the root and child nodes depending on the results of your
comparison.

Thanks,

Seth Rowe
 
R

Robinson

Possible list on my Tree View:


PRIMARY
Primary 1.1
Primary 1.2
SECONDARY
Secondary 1.1
Seconday 1.2


Can anyone give me possible Code? including SQL Connection..


Hi,

It seems from what I see above, that you are attempting to solve one of
those non-trivial problems in CS, i.e. storing and manipulating a tree
structure in a database. The problem with hard coding rules is that the
number increases exponentially with the level or "depth" of the tree. In
your example you have two levels, which is fairly trivial, but might you
want to expand to 4, 8 or "n" levels in future? If that is the case, you
need to write some serious plumbing (preferably in stored procedures) to
implement a generalized tree structure. There are a few solutions that
spring to mind that you could research. Celko has written widely on this
subject (google: Celko+Tree Structure In Database). The method I personally
prefer however involves storing a Parent ID and Path String with each "node"
(record) in my database. By doing this it's possible to select sub-trees
using the "LIKE" predicate. Building a tree from a set of records is quite
simple if you can get the records back in tree order (order by "Path" ASC).

If you would like further information on how to do this, I might be able to
provide some, having scratched my head over this problem during the last
three years of my work-life ;).



Robin
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top