当前位置:编程学习 > C#/ASP.NET >>

关于TREE递归 ,加载数据库表的问题

大伙帮我看看我的代码.


Private Sub TreeFullData(ByVal tnParentNode As TreeNode, ByVal str As String)   '此过程用在展开树,STR变量为TREE点中的变量值,用此值,查询出下阶物料值,付给TREE.
        Dim trnchildentNode As New TreeNode
        Dim sql As String
        Dim texCurrentNode As String
        Dim position As Integer
        Dim oRec As SAPbobsCOM.Recordset
        Dim i As Integer = 0
        Try
           
            oRec = oCompany.GetBusinessObject(SAPbobsCOM.BoObjectTypes.BoRecordset)

            sql = "exec U_BomSelect '" & str & "'"   '这是通过存储过程,获取结点号
            oRec.DoQuery(sql)

            If oRec.RecordCount > 0 Then

                Do Until oRec.EoF
                    texCurrentNode = oRec.Fields.Item("U_CurItem").Value
                    trnchildentNode.Text = texCurrentNode
                    tnParentNode.Nodes.Add(trnchildentNode)
                    TreeFullData(trnchildentNode, texCurrentNode)
                    oRec.MoveNext()
                Loop
            End If

        Catch ex As Exception
            System.Windows.Forms.MessageBox.Show(ex.Message)
        Finally
            oRec = Nothing
            sql = Nothing
            str = Nothing
            tnParentNode = Nothing
            trnchildentNode = Nothing
            texCurrentNode = Nothing

        End Try
    End Sub


这是一个加载数据库表的代码.从结构上来看,应该没有问题,但在运行时,会出现错误,并且结果是错误的.

错误提示是错误的提示是" Cannot add or insert then item""............"
--------------------编程问答-------------------- 把Dim trnchildentNode As New TreeNode 这一句放到Do Until里面去 --------------------编程问答-------------------- 还有你texCurrentNode的定义完全没意义
texCurrentNode = oRec.Fields.Item("U_CurItem").Value 
trnchildentNode.Text = texCurrentNode 
这两句为什么不合并成
trnchildentNode.Text = oRec.Fields.Item("U_CurItem").Value
呢? --------------------编程问答-------------------- Dim trnchildentNode As New TreeNode 
放在   Do Until oRec.EoF 内部
参考
参考 --------------------编程问答-------------------- ... --------------------编程问答-------------------- 3楼正解.
补充:.NET技术 ,  VB.NET
CopyRight © 2012 站长网 编程知识问答 www.zzzyk.com All Rights Reserved
部份技术文章来自网络,