[.NET] TreeView 抓Access 資料並顯示成節點,子節點問題

看板Visual_Basic作者 (紫)時間14年前 (2011/09/28 18:32), 編輯推噓0(000)
留言0則, 0人參與, 最新討論串1/1
請輸入專案類型(網站專案或者應用程式專案):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
文章代碼(AID): #1EWlVKnj (Visual_Basic)