asp_web_howto thread: Recursive subroutine with ADO...
I am writing a pure ASP/VBScript/JavaScript treeview system which is driven by a
database. In order to display the tree, my thought was to use a recursive
subroutine to traverse the parent child relationship in the database.
Before I start to write the code, I can think of a problem which is defining my
recordset names. If I am in the middle of looping through a recordset for one
group of records, and I call myself, how do I open another recordset? My
assumption is that I need to reference each recordset uniquely.
Consider a table with the fields ID, Parent, Action.
The call to the subroutine mifght be
call DisplayTree("root",0)
the subroutine might be
Sub DisplayTree(parent,level)
level = level + 1
set RsTree = Server.CreateObject("ADODB.Recordset")
RsTree.ActiveConnection = "Provider=Microsoft.Jet.OLEDB.4.0; Data
Source=\myweb\mydb.mdb"
RsTree.Source = "SELECT * FROM TREEVIEW"
RsTree.Open()
While (NOT rsTree.EOF)
if RsTree("Action") = "folder"_
then
call DisplayTree(RsTree("ID"),level) ' this is the recursive bit
else
'do some ASP type stuff...
end if
rsTree.MoveNext()
Wend
RsTree.Close()
End Sub
What I forsee as my problem, is that I have the recordset RsTree open, and I
call myself which will attempt to reopen the recordset, which I think will fail.
Any ideas on how to change the name of the cursor for each iteration (level) of
the call.
Paul