你要的代码来了,这就是用VB中的Treeview来连接数据库了!!!
Private Sub Form_Load()
Dim cnode As Node
Dim strSql As String
dim conn As New ADODB.Connection
Dim rs As ADODB.Recordset
Dim cnode As Node
'text.mdb改成你的Access数据库名
With conn
If .State = adStateClosed Then
.ConnectionString = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" & App.Path & "/text.mdb;Persist Security Info=False"
.Open
End If
End With
Set cnode = treeview1.Nodes.Add(, ,"one" , "根节点")
strSql = "select * from 部件表"
Set rs = OpenRecordset(strSql)
Do While Not rs.EOF
Set cnode = treeview1.Nodes.Add("one", tvwChild,"K" & rs!Name , rs!Name)
rs.MoveNext
Loop
For i = 1 To TreeView1.Nodes.Count
TreeView1.Nodes(i).Expanded = True
Next
数据库建立好后,把上面的代码复制进去看结果吧!!!