Question Treenodes saved in database

franz081227

Member
Joined
Sep 1, 2008
Messages
8
Programming Experience
Beginner
Guys help me I have this 4 tables. My problem is I have to save the treeNodes in the 4 tables. How can I determine that a specific treenode will be save in one specific table??

The format of the treenodes is like this:

VB.NET:
Cat_tab
	SubCat_tab
	SubCat_tab
		Exp_tab
		Exp_tab
			ExpDet_tab
Cat_tab
	SubCat_tab
		Exp_tab
		Exp_tab
		         ExpDet_tab

i have a code to retrieve it to the different tables and it's like this

VB.NET:
Public Sub B_CAT()
        Dim strCat As String
        Dim rsCat As New ADODB.Recordset
        Dim CatNo As Integer = 0



        tvAccounts.Nodes.Clear()

        strCat = "Select accountCatNo, accountCatDesc from accountCategory_tab"

        With rsCat
            .Open(strCat, conn)
            Do While Not .EOF
                Dim tvNode As New TreeNode
               
                tvNode.Text = .Fields(1).Value

                tvAccounts.Nodes.Add(tvNode)

                B_SUBCAT(CatNo, .Fields(0).Value)

                CatNo += 1
                .MoveNext()
            Loop
            .Close()
        End With
    End Sub

    Public Sub B_SUBCAT(ByVal catno As Integer, ByVal AcctCatNo As Integer)
        Dim strSubCat As String
      
        strSubCat = "Select accountSubCatID, accountSubCatDesc from accountSubcategory_tab" & _
        " where accountCatNo=" & AcctCatNo

        With rsSubCat
            .Open(strSubCat, conn)
            Do While Not .EOF
                Dim tvNode As New TreeNode
                Dim strSaveSubCat As String
                Dim rsSaveSubCat As New ADODB.Recordset

                tvNode.Text = .Fields(1).Value

                tvAccounts.Nodes(catno).Nodes.Add(tvNode)

                B_EXP(catno, SubCatNo, .Fields(0).Value)

              
                SubCatNo += 1
                .MoveNext()
            Loop
            .Close()
        End With
    End Sub

    Public Sub B_EXP(ByVal catNo As Integer, ByVal subCatNo As Integer, ByVal AcctSubCatID As String)
        Dim strExp As String
        Dim rsExp As New ADODB.Recordset
        Dim expNo As Integer = 0

        strExp = "Select expenseID, expensedesc from accountexpense_tab where accountSubCatID='" & AcctSubCatID & "'"

        With rsExp
            .Open(strExp, conn)
            Do While Not .EOF
                Dim tvNode As New TreeNode
       

                tvNode.Text = .Fields(1).Value
                tvAccounts.Nodes(catNo).Nodes(subCatNo).Nodes.Add(tvNode)


                B_EXPDET(catNo, subCatNo, expNo, .Fields(0).Value)

              
                expNo += 1
                .MoveNext()
            Loop
            .Close()
        End With
    End Sub

    Public Sub B_EXPDET(ByVal catNo As Integer, ByVal subcatNo As String, ByVal expNo As Integer, ByVal acctExpID As String)
        Dim strExpDet As String
        Dim rsExpDet As New ADODB.Recordset


        strExpDet = "Select expenseDetailsNo, expenseDetailsDesc from accountexpensedetail_tab where expenseID='" & acctExpID & "'"

        With rsExpDet
            .Open(strExpDet, conn)
            Do While Not .EOF
                Dim tvNode As New TreeNode
                
                tvNode.Text = .Fields(1).Value
                tvAccounts.Nodes(catNo).Nodes(subcatNo).Nodes(expNo).Nodes.Add(tvNode)


               
                .MoveNext()
            Loop
            .Close()
        End With
    End Sub
 
Last edited by a moderator:
First up, I suggest you stop using ADO and start using ADO.NET. Unless this is an upgraded VB6 application there really is no reason to be using ADO.

As for the question, you have several options, which include:

1. Use the Level property of each node. Nodes with a level of 0 will be Cat nodes, Subcat will be 1, Exp 2 and ExpDet 3.

2. Use the Tag property of each node to store a value that indicates the source table.

3. Derive your own class from TreeNode and add a property that identifies the source table.
 
Do what? ADO.NET or one of the three choices for identifying nodes? If it's one of those three choices, which one? Did you do any investigation for yourself first? Did you read about the Level and or Tag properties of the TreeNode class, for instance?
 
any suggestion wer can i read those topics???/
Use the Help menu in Visual Studio .NET to open the MSDN Library documentation. Using the Help menu is the first thing ANY user should do no matter what software they're using.
 
Back
Top