Решено с помощью этого кода:
Private Sub InitTree()
'Populate table here.
TreeView1.Nodes.Clear()
Try
Dim sqlconstr As String
sqlconstr = MainForm.Label1.Text
' CONNECTION
Dim dt As New DataTable
Dim con As New SqlConnection(sqlconstr)
Dim Da As New SqlDataAdapter("Select [Parentname], [name] from [dbo].[GR] order by [Parentcode] asc , [code] asc", con)
dt.Clear()
Da.Fill(dt)
If dt.Rows.Count > 0 Then
For Each dr As DataRow In dt.Rows
AddNode(dr("Parentname").ToString, dr("name").ToString)
Next
Else
' TreeView1.Nodes.Add("hgvzds")
End If
Catch ex As Exception
MsgBox(ex.Message)
End Try
TreeView1.ExpandAll()
End Sub
Private Sub AddNode(parentNode As String, nodeText As String)
Dim node As New List(Of TreeNode)
node.AddRange(TreeView1.Nodes.Find(parentNode, True))
If Not node.Any Then
node.Add(TreeView1.Nodes.Add(parentNode, parentNode))
End If
node(0).Nodes.Add(nodeText, nodeText)
End Sub