Hi NG,
After a break of two months I am back on my project of converting a COBOL
ERP product to C# and SQL Server. I now have to process a tree structure in
C#. Not only am I a newbie in C#, but SQL as well. So if these questions
sound stupid, please forgive me. All of my programming in C# to date, with
one exception, has been to "ask" SQL for a specific primary key. That
exception has been to fill a C# data table with all of the rows from a SQL
table. The process for the tree structure is a tad different. The tree's
primary key has 2 parts: a parent part number and a component part number.
The COBOL procedure makes use of the fact that the data is stored in an ISAM
file. By definition the index is in sequential order. It is easy to ask
COBOL for the first parent and store its component. Then see if that
component is a parent to some other component. From anywhere in the tree
you can always ask for the next sequential record and of course you can ask
for the first record. I can not figure out how to ask SQL for the first row
of a table. Further, I do not know how to ask for a row where I know the
parent, but not the component. Consider the following tree:
Parent Component
500-000 500-001
500-000 500-004
500-000 500-005
500-000 500-006
500-000 500-100
500-004 500-080
500-005 500-080
500-100 500-002
500-100 500-003
This is one tree. In the real case there would be many trees. Task 1 is to
ask SQL for the first row. In my past C# programs I would know what the
whole key is, 500-000 500-001 in this case. Now I do not know the key. How
do I ask for the first row? Next, I would want to check if the component,
500-001, is a parent (it is not). How do I ask SQL if any row begins with
500-001? The component of row 2 is in fact a parent. Asking SQL about this
component as parent should produce row 6.
My understanding of this issue would be greatly advanced if I could process
this table as a sequential file. For example I would like to ask SQL to
find the first parent that was equal to 500-100. Then I would like to ask
for the next parent that was 500-100 until it could find no more. In that
case it would find 2 rows starting at row 8.
If it would help I can supply the code I am using to get particular rows
when I know the full key to ask SQL.
Thanks in advance,
Bob
--
Robert Schuldenfrei
S. I. Inc.
32 Ridley Road
Dedham, MA 02026
bo*@s-i-inc.com
781/329-4828