经典ASP递归函数

发布于 2024-08-31 01:52:36 字数 1049 浏览 4 评论 0原文

我已经有几年没有做过任何经典的 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

情话墙 2024-09-07 01:52:36

全局范围内有一个 objRsTmp 实例,这意味着它在堆栈上的每个 buildList() 之间共享;因此,每当您递归到 buildList() 并调用 objRsTmp.Open() 时,都会导致堆栈上先前的 buildList() 使用新的objRsTmp。

我不认为这就是您所追求的,因为您循环其行,就好像每个 buildList() 都有自己的一组结果一样。

为此,您必须将记录集设置为本地...但是,这是一种非常昂贵的方法,特别是因为每次迭代还创建一个新的连接对象。

根据您的架构/关系型数据库,通常有一种单查询方式来提取一组分层相关的记录。

There is a single instance of objRsTmp in global scope, meaning its shared between every buildList() on the stack; so whenever you recurse into buildList() and call objRsTmp.Open() your causing the prior buildList() on the stack to use the new objRsTmp.

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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文