ASP Classic to VB.NET - 包括记录集在内的递归函数



我希望有人能帮助我想出这个问题,因为我被困住了。

我们正在慢慢地将 ASP Classic 网站迁移到 .NET Web 应用程序。我偶然发现了以下功能。该函数将返回一个由 hml a 标签组成的字符串数组。

Private Function getFullPathLinks(lNodeId, sPath, sDocTemplate)
    Dim sql, recordSet, rsTmp
    Dim arrPath, sResult
    Dim lDocId
    lDocId  = getDocumentId(lNodeId)
    sql = "SELECT parent_id, label FROM wt_node WHERE (node_id = " & lNodeId & ")"
    Set recordSet = execSqlCache(oConn,sql,Array(),Array("wt_node"))
    If Not (recordSet.Bof And recordSet.Eof) Then
        If sDocTemplate <> "" Then
            sPath = sPath & "|" & "<a href='" & sDocTemplate & "?nodeid=" & lNodeId & "&documentid=" & lDocId & "'>" & recordSet("label") & "</a>"
        Else
            sPath = sPath & "|" & recordSet("label")
        End If

        getFullPathLinks recordSet("parent_id"), sPath
    End If
    recordSet.Close
    Set recordSet = Nothing
    arrPath = arrReverse(Split(sPath,"|"))
    sResult = Join(arrPath,sPathDelimiter)
    If Right(sResult,Len(sPathDelimiter)) = sPathDelimiter Then sResult = Left(sResult,Len(sResult)-Len(sPathDelimiter))
    getFullPathLinks    = sResult
End Function

该函数在最后调用自身,这在我的 .NET 实现中效果不佳,我们使用 DataReader 与 SQL 数据库通信。

我可以遵循与上面相同的结构,而是使用 DataReader 以外的其他东西来实现这一点吗?

我不确定您使用的是哪个SQL Server版本,但是您是否看过SQL中的递归查询?它旨在检索单个数据库调用中的分层数据。看一看:

http://msdn.microsoft.com/en-us/library/ms186243(v=sql.105).aspx

最新更新