作者opqisgod (紫)
看板Visual_Basic
标题[.NET] TreeView 抓Access 资料并显示成节点,子节点问题
时间Wed Sep 28 18:32:49 2011
请输入专案类型(网站专案或者应用程式专案):VS2010
参照网路上提供的范例制作了一个专案
Access(DB2)内table(test2)
http://imageshack.us/photo/my-images/836/22127796.jpg/
问题: 请问用VS2010侦错与直接执行debug资料夹内的程式Treeview结果怎麽都不同?
VS2010侦错:
http://imageshack.us/photo/my-images/713/debug2.jpg/
Debug资料夹:
http://imageshack.us/photo/my-images/820/debugx.jpg/
我有试过将DB内资料重新排序或捞资料时排序,但VS2010执行结果都不行与debug相同
请问是否有地方写错? 谢谢前辈指教!
程式码如下:
Imports System.Data.OleDb
Public Class Form1
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles Me.Load
Dim cn As New OleDbConnection("provider=microsoft.Jet.OLEDB.4.0;Data
source= DB2.mdb ")
Dim cmd As New OleDbCommand("Select * from test2", cn)
Dim da As New OleDbDataAdapter
Dim ds As New DataSet
da.SelectCommand = cmd
da.Fill(ds, "test2")
DataGridView1.DataSource = ds.Tables("test2")
Keyword_txt.Text = ds.Tables("test2").Rows.Count
Dim temp_s, temp_d As String
For i As Integer = 0 To ds.Tables("test2").Rows.Count - 1
Dim dr As DataRow = ds.Tables("test2").Rows(i)
temp_s = dr(0)
temp_d = dr(1)
If temp_d = "0" Then
TreeView1.Nodes.Add(temp_s)
Else
search_node(TreeView1.Nodes, 0, temp_s, temp_d)
End If
Next i
TreeView1.ExpandAll()
End Sub
Public Sub search_node(ByVal tnc As TreeNodeCollection, ByVal c As
Integer, ByVal s As String, ByVal d As String)
Dim i As Integer
For i = 0 To tnc.Count - 1
If tnc(i).Text = d Then
tnc(i).Nodes.Add(s)
Else
search_node(tnc(i).Nodes, i, s, d)
End If
Next
End Sub
End Class
--
※ 发信站: 批踢踢实业坊(ptt.cc)
◆ From: 59.125.82.148