RE: Recursive function help
From: Tim M (TimM_at_discussions.microsoft.com)
Date: 07/28/04
- Next message: prschmid: "Re: Multi Language Site"
- Previous message: Jeff Cochran: "Re: Application Object"
- In reply to: JP SIngh: "Recursive function help"
- Next in thread: Ray at <%=sLocation%> [MVP]: "Re: Recursive function help"
- Messages sorted by: [ date ] [ thread ]
Date: Wed, 28 Jul 2004 07:15:05 -0700
You open dbRS in GetParents() and then you try to use it again in GetReplies(). You need to explicitly define objects like these and other variables so you can be clear about their scope. (eg dim dbRs, conn, ...) You should also have the Option Explicit declaration at the start of the page.
You could use a single query and return all employees sorted in to levels and use nested do while loops or a recursive function.
Tim M
"JP SIngh" wrote:
> Hi All
>
> I am trying to write a recursive function to list the managers and his
> employees in a tree like sctructure
>
> Manager 1
> Emp1
> Emp1.1
> Emp 1.2
> Emp 2
> Emp 3
> Emp 3.1
> Emp 3.2
>
> Have written the following code but don't seems to be getting anywhere
>
> It gives me this error
>
> Microsoft VBScript runtime error '800a01fb'
> An exception occurred: 'dbRS.Open'
> /admin/man.asp, line 20
> Someone please help
>
> Regards
>
> Jas
>
> <%
> set conn = Server.Createobject("ADODB.Connection")
> conn.Provider = "Microsoft.Jet.OLEDB.4.0"
> conn.Open "D:\Applications\Holidays12004\Includes\holidays.mdb"
> Getparents()
>
> Function GetParents()
> Set dbRS = Server.CreateObject("ADODB.Recordset")
> ' ADO code to load all the posts with a null parent
> dbRS.Open "SELECT * FROM empprofile order by managername", conn
> Do While Not dbRS.EOF
> GetReplies(dbRS.Fields("empname"))
> dbRS.MoveNext
> Loop
> End Function
>
> Function GetReplies(parentID)
> Set dbRS = Server.CreateObject("ADODB.Recordset")
> dbRS.Open "SELECT * FROM empprofile WHERE managername = '" & parentid &
> "'", conn
> Do While Not dbRS.EOF
> Response.write "mangername = " & dbRS.Fields("managername") & "
> empname = " & dbRS.Fields("empname") & "<br>"
> ' <-- Your recursive call. Walks down each tree branch until
> ' it hits the last reply in a tree (dbRS returns no rows), then backs
> out.
> GetReplies(dbRS.Fields("empname"))
> dbRS.MoveNext
> Loop
> End Function
> %>
>
>
>
- Next message: prschmid: "Re: Multi Language Site"
- Previous message: Jeff Cochran: "Re: Application Object"
- In reply to: JP SIngh: "Recursive function help"
- Next in thread: Ray at <%=sLocation%> [MVP]: "Re: Recursive function help"
- Messages sorted by: [ date ] [ thread ]
Relevant Pages
|