数据库的一张表怎么样用树型显出来?
[attach]69114[/attach]表名称playlist 表字段Id tvclass tvclassid tvname tvurl 怎么样用树型控件显示出,俺水平有限,请各位老师指点一下
[ 本帖最后由 dafunlang 于 2013-3-5 19:49 编辑 ]
程序代码: rs.Open "select * from playlist ", Conn, adOpenKeyset, adLockReadOnly
Do Until rs.EOF
Dim cid As Long
cid = rs("tvclassid")
Select Case cid
Case 0
If Not IsNull(rs("tvclass")) Then
Set nodX = TreeView1.Nodes.Add(, , "K" & rs("id"), rs("tvclass"))
Else
Set nodX = TreeView1.Nodes.Add(, , "K" & rs("id"), "(Null)")
End If
Case Is > 0 ' Is > 0 ' else ' 有负数?神马情况?
If Not IsNull(rs("tvname")) Then
Set nodX = TreeView1.Nodes.Add("K" & cid, tvwChild, "K" & rs("id"), rs("tvname")) 'TreeRelationshipConstants tvwChild
Else
Set nodX = TreeView1.Nodes.Add("K" & cid, tvwChild, "K" & rs("id"), "(Null)")
End If
End Select
rs.MoveNext
Loop
rs.Close
也可以善用 Key。
程序代码:
Private Sub TreeView1_NodeClick(ByVal myNode As MSComctlLib.Node)
Dim rs As ADODB.Recordset
If Not myNode.Parent Is Nothing Then
Set rs = New ADODB.Recordset
rs.Open "select * from playlist where id=" & Mid$(myNode.Key, 2), Conn, adOpenKeyset, adLockReadOnly
'wmp1.URL = rs("tvurl")
Debug.Print rs("tvurl")
rs.Close
End If
Set rs = Nothing
End Sub
写这代码时咱想到了2楼。