添加TreeView控件,2个按钮
2个按钮分别用了两种方法显示数据。但是第二种方法明显优于第一种。
可以仔细的看代码
'引用microsoft activex data object 2.x library
Dim nddata As Node
Dim cnn As ADODB.Connection
Dim rs1 As New ADODB.Recordset
Dim rs2 As New ADODB.Recordset
Private Sub Command1_Click()
On Error Resume Next
Set nddata = TreeView1.Nodes.Add(, , "db", "班级信息")
nddata.Expanded = True
Dim intcount As Integer
Dim inttable As Integer
Dim intfield As Integer
Dim intfn As Integer
rs1.Open "select nj from test group by nj", cnn, 1, 3
inttable = rs1.RecordCount
Do While inttable <> intcount
Set nddata = TreeView1.Nodes.Add("db", tvwChild, "F" & rs1.Fields("nj"), rs1.Fields("nj"))
rs2.Open "select bh,nj from test where nj='" & rs1.Fields("nj") & "'", cnn, 1, 3
intfield = rs2.RecordCount
If intfield <> 0 Then
intfn = 0
Do While intfield <> intfn
Set nddata = TreeView1.Nodes.Add("F" & rs1.Fields("nj"), tvwChild, "S" & rs2.Fields("bh"), rs2.Fields("bh"))
rs2.MoveNext
intfn = intfn + 1
Loop
End If
rs2.Close
rs1.MoveNext
intcount = intcount + 1
Loop
rs1.Close
End Sub