经典ASP递归函数
我已经有几年没有做过任何经典的 ASP 了,现在尝试从 C# 重新开始它被证明是不可能的!我有一个递归函数,它非常简单地应该根据传递给函数的值查询数据库,一旦函数停止调用自身,它就会返回记录集......但是我收到旧错误“80020009”消息。我已在函数外部声明了记录集。
有人能看到我的方式中的错误吗?
Dim objRsTmp
Function buildList(intParentGroupID)
Set objRsTmp = Server.CreateObject("Adodb.Recordset")
SQLCommand = "SELECT * FROM tblGroups WHERE tblGroups.intParentGroupID = " & intParentGroupID & ";"
objRsTmp.Open SQLCommand, strConnection, 3, 3
If Not objRsTmp.Eof Then
While Not objRsTmp.Eof
Response.Write(objRsTmp("strGroup") & "<br />")
buildList(objRsTmp("intID"))
objRsTmp.MoveNext
Wend
End If
Set buildList = objRsTmp
'#objRsTmp.Close()
'Set objRsTmp = Nothing
End Function
Set objRs = buildList(0)
If Not objRs.Eof Then
Response.Write("There are records")
While Not objRs.Eof
For Each oFld in objRs.Fields
Response.Write(oFld.Name & ": " & oFld.Value & ",")
next
Response.Write("<br />")
objRs.MoveNext
Wend
End If
任何帮助将不胜感激。
问候, 铝
I havent done any classic ASP for a couple of years and now trying to get back into it from c# is prooving impossible! I've got a recursive function which very simply is supposed to query a database based on a value passed to the function and once the function has stopped calling itself it returns the recordset....however im getting the old error '80020009' message. I've declared the recordset outside of the function.
Cany anyone see the error in my ways?
Dim objRsTmp
Function buildList(intParentGroupID)
Set objRsTmp = Server.CreateObject("Adodb.Recordset")
SQLCommand = "SELECT * FROM tblGroups WHERE tblGroups.intParentGroupID = " & intParentGroupID & ";"
objRsTmp.Open SQLCommand, strConnection, 3, 3
If Not objRsTmp.Eof Then
While Not objRsTmp.Eof
Response.Write(objRsTmp("strGroup") & "<br />")
buildList(objRsTmp("intID"))
objRsTmp.MoveNext
Wend
End If
Set buildList = objRsTmp
'#objRsTmp.Close()
'Set objRsTmp = Nothing
End Function
Set objRs = buildList(0)
If Not objRs.Eof Then
Response.Write("There are records")
While Not objRs.Eof
For Each oFld in objRs.Fields
Response.Write(oFld.Name & ": " & oFld.Value & ",")
next
Response.Write("<br />")
objRs.MoveNext
Wend
End If
Any assistance would be greatly appreciated.
Regards,
Al
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
全局范围内有一个
objRsTmp
实例,这意味着它在堆栈上的每个buildList()
之间共享;因此,每当您递归到buildList()
并调用objRsTmp.Open()
时,都会导致堆栈上先前的buildList()
使用新的objRsTmp。我不认为这就是您所追求的,因为您循环其行,就好像每个
buildList()
都有自己的一组结果一样。为此,您必须将记录集设置为本地...但是,这是一种非常昂贵的方法,特别是因为每次迭代还创建一个新的连接对象。
根据您的架构/关系型数据库,通常有一种单查询方式来提取一组分层相关的记录。
There is a single instance of
objRsTmp
in global scope, meaning its shared between everybuildList()
on the stack; so whenever you recurse intobuildList()
and callobjRsTmp.Open()
your causing the priorbuildList()
on the stack to use the newobjRsTmp
.I don't think this is what your after as your looping its rows as though every
buildList()
had its own set of results.To do that you would have to make the recordset local... however, that's a *very expensive way to do it, particularly because each iteration is also creating a new connection object.
Depending on your schema/rdbms there is usually a single-query way to pull of a set of hierarchically related records.