Results 1 to 2 of 2

Thread: Building TreeView from Database

  1. #1

    Thread Starter
    Fanatic Member steve65's Avatar
    Join Date
    Jun 2000
    Posts
    610

    Building TreeView from Database

    Hi all,

    I am trying to populate a TreeView using an Access database. I have been able to get the first set of braches in but I have not been able to completely get sub nodes in. The first node comes in just fine but each node to follow includes the nodes above it. So I know I am not closing my datasets right but I am not sure what I am doing wrong. Do you see what I am doing wrong?

    Thanks Steve
    Code:
            Dim MyAdapter As New OleDbDataAdapter
            Dim MyDataset As New DataSet
            Dim MyCommand As New OleDbCommand
            Dim MyRow As DataRow
            Dim MyNode As TreeNode
    
            Me.tvCodeLibrary.Nodes.Clear()
    
            MyCommand = New OleDbCommand("SELECT Name FROM CodeSection ORDER By Name", MyConnection)
            MyAdapter = New OleDbDataAdapter(MyCommand)
            MyAdapter.Fill(MyDataset, "CodeSection")
            For Each MyRow In MyDataset.Tables("CodeSection").Rows
                Me.tvCodeLibrary.Nodes.Add(MyRow(0))
            Next MyRow
    
            For Each MyNode In Me.tvCodeLibrary.Nodes
    
                MyCommand = New OleDbCommand("SELECT Name from Code where SectionID = (SELECT ID FROM CodeSection WHERE Name = '" & MyNodes.Text & "') ORDER BY Name", MyConnection)
                MyAdapter = New OleDbDataAdapter(MyCommand)
                MyAdapter.Fill(MyDataset, "Name")
    
                For Each MyRow In MyDataset.Tables("Name").Rows
                    MyNode.Nodes.Add(MyRow(0))
                Next MyRow
    
            Next MyNode
    
            MyDataset.Dispose()
            MyAdapter.Dispose()
            MyCommand.Dispose()
    This space for rent...

  2. #2

    Thread Starter
    Fanatic Member steve65's Avatar
    Join Date
    Jun 2000
    Posts
    610
    For those interested here is where I messed up. I needed to add MyDataset.Tables("CodeSection").Clear() and MyDataset.Tables("Name").Clear()
    This space for rent...

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width