Looping Nested Query Results (DataReader Woes)

Joined
Mar 24, 2007
Messages
3
Reaction score
0
I am connecting to an Oracle database using an OleDbConnection. I am using DataReader objects to get query results. However, this limits me to only having one datareader open at a time, which is a problem for one of the operations I am doing.

I have a table with hierarhical data (only 3 levels deep) that I would like to parse through in a depth-first search. Each row in the table in the database has a Name and a ParentName, and I'm doing something like this:

oCmd1 = New OleDbCommand( "Select Name from tblTree where parentName='_top'", oCxn )
oRdr1 = oCmd1.ExecuteReader()

While oRdr1.Read()
sName1 = oRdr1("Name")
oCmd2 = New OleDbCommand( "Select Name from tblTree where parentName='" & sName1 & "'", oCxn )
oRdr2 = oCmd2.ExecuteReader()

While oRdr2.Read()
' do the third level, you get the idea
End While
oRdr2.Close()

End While
oRdr1.Close()

The problem is, it won't let me use oRdr2 while oRdr1 is open; and I can't close oRdr1 because it is still in the middle of cycling through the top-level items.

SO, my question is this: What is the PREFERRED way of dealing with this?

The options seem to be:

1) create a new DB connection for each level in the hierarchy
2) move to a different kind of object (DataSet?), instead of a DataReader
3) ??????.... some other option I haven't thought of?

I don't know which approach would be best, or if there are other approaches I'm not thinking of. Any help or advice is greatly appreciated.

Also, I apologize if this question would be better suited to a different forum. Please just let me know, and I'll take it there.

Thanks!
--- Greg Stevens
 

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

Members online

No members online now.

Forum statistics

Threads
473,989
Messages
2,570,207
Members
46,783
Latest member
RickeyDort

Latest Threads

Top