Filling a treeview from mysql


Apr 26, 2005
Programming Experience
I am trying to fill a treeview in from a mysql database. I want to have 3 levels, i.e. parent, child and grandchild!

My code connects to the mysql database with no problem and reads the parent name into the correct place in the treeview and also the grandchild, BUT the child (middle node) is just a number in the treeview taken from the relation database. I have highlighted the part i think is the problem. It does not read the name. HELP!

Here is my code:

Dim db As DataSet

Dim test As New OdbcConnection("")

Dim relation2 As New OdbcDataAdapter("SELECT parent_id, child_id, gene_id FROM relation2", test)

Dim parent As New OdbcDataAdapter("SELECT id, name FROM parent", test)

Dim child As New OdbcDataAdapter("SELECT id, names, GO_number FROM child", test)

Dim gene As New OdbcDataAdapter("SELECT id, HUGO FROM gene ", test)

db = New DataSet


relation2.Fill(db, "relation2")

parent.Fill(db, "parent")

child.Fill(db, "child")

gene.Fill(db, "gene")


db.Relations.Add("ParentToRelation2", db.Tables("parent").Columns("id"), db.Tables("relation2").Columns("parent_id"))

db.Relations.Add("Relation2ToChild", db.Tables("relation2").Columns("child_id"), db.Tables("child").Columns("id"))

db.Relations.Add("Relation2Togene", db.Tables("relation2").Columns("gene_id"), db.Tables("gene").Columns("id"))



Dim i, n As Integer

Dim parentrow As DataRow

Dim ParentTable As DataTable

Dim ChildTable As DataTable

Dim Y As DataRow

Dim ChildTableRows As DataTable

ParentTable = db.Tables("parent")

'relation2.tables? "parentToRelation2"

For Each parentrow In ParentTable.Rows

Dim parentnode As TreeNode

parentnode = New TreeNode(parentrow.Item(1))


''''populate child'''''


Dim childrow As DataRow

Dim childnode As TreeNode

childnode = New TreeNode

' This is looking at the parent table

For Each childrow In parentrow.GetChildRows("ParentToRelation2")

childnode = parentnode.Nodes.Add(childrow(1) & "(" & childrow(0) & ")")

childnode.Tag = childrow("child_id")

''''populate child2''''


Dim childrow2 As DataRow

Dim childnode2 As TreeNode

childnode2 = New TreeNode

For Each childrow2 In childrow.GetChildRows("Relation2Togene")

childnode2 = childnode.Nodes.Add(childrow2("HUGO"))

Next childrow2


Next childrow


Next parentrow

End Sub

Thankyou for your help in advance
Top Bottom