請各位大神幫忙,確定TREEVIEW1裡面有很多節點,treeview1.nodes.count只有1個? Private Sub Button7_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button7.Click
mycn.ConnectionString = "Data Source=" & ControlC.TextBox2.Text & ";Initial Catalog=blue;uid=maseru;pwd=Wks123"
Dim i As Integer
For i = 1 To TreeView1.Nodes.Count - 1
Dim k1 As String = TreeView1.Nodes(i).Name
Dim TF As Boolean
If TreeView1.Nodes(i).Checked = True Then
TF = "1"
Else
TF = "0"
End If
Dim mycom As New SqlClient.SqlCommand
mycom.CommandText = "update PrivilegeUser set puTF =" & TF & " where puRID ='" & TextBox1.Text & "' and puPriID ='" & k1 & "' "
mycom.Connection = mycn
Try
mycn.Open()
Dim mysqlreader As Data.SqlClient.SqlDataReader = mycom.ExecuteReader
mycom.ExecuteNonQuery()
Catch ex As Exception
End Try
Next
End Sub
你需要用遞歸去遍歷每一級節點,他的節點數不是指的所有的,而是這一級上的節點數