各位大虾高手快来帮帮我啊,VB+SQL 2005 中treeview使用
我用VB的treeview控件来实现结点的添加,并写入数据库中,但是运行了有错误啊,改了很久一直改不出来Public Sub Add_DepToTree(TreeView1 As TreeView, ByVal TmpKey As String)
Dim dID As String
Dim TmpNode As Node
Dim CurKey As String
Dim strSql As String
Dim rs1 As New ADODB.Recordset
Dim rs2 As New ADODB.Recordset
dID = Right(TmpKey, Len(TmpKey) - 1)
strSql = "select DepId,DepName from Departments where UpperId='" & Trim$(dID) & "'order by DepName"
rs1.Open strSql, Conn, adOpenStatic, adLockReadOnly
Do Until rs1.EOF
If rs2.State = adStateOpen Then rs2.Close
CurKey = "a" & rs1!DepId
strSql = "select count(*) as d_count from Departments where UpperId='" & Trim$(rs1!DepId) & "'"
rs2.Open strSql, Conn, adOpenStatic, adLockReadOnly
If rs2!d_count > 0 Then
Set TmpNode = TreeView1.Nodes.Add(TmpKey, tvwChild, CurKey, rs1!DepName, 2)
Set TmpNode = TreeView1.Nodes.Add(TmpKey, tvwChild, CurKey, rs1!DepName, "imgClosedFolder") ‘总是在这个位置出错,调试提示 key is not unique in collection’ 我看了很久都没有看出哪儿的毛病
TmpNode.ExpandedImage = "imgOpenedFolder"
Call Add_DepToTree(TreeView1, CurKey)
Else
Set TmpNode = TreeView1.Nodes.Add(TmpKey, tvwChild, CurKey, rs1!DepName, "imgDeselectedFile", "imgSelectedFile")
End If
rs2.Close
Set rs2 = Nothing
rs1.MoveNext
Loop
rs1.Close
Set rs1 = Nothing
End Sub 看着你这一堆代码,就眼花了,难怪没人理你 key是唯一的,你的sql有问题 key is not unique in collection:key不是唯一的,说明你添加的节点的key与已经添加的节点的key有重复。
补充:VB , 控件