1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68
| Private Sub BT_Enregistrer_Click(sender As Object, e As EventArgs) Handles BT_Enregistrer.Click
Call Savetotable()
End Sub
Private Sub PrintRecursive(ByVal n As TreeNode)
System.Diagnostics.Debug.WriteLine(n.Text)
MessageBox.Show(n.Text)
Dim aNode As TreeNode
For Each aNode In n.Nodes
PrintRecursive(aNode)
Next
End Sub
Private Sub CallRecursive(ByVal aTreeView As TreeView)
Dim n As TreeNode
For Each n In aTreeView.Nodes
PrintRecursive(n)
Next
End Sub
Private Sub Savetotable()
'id int identity(1,1)not null unique,
'id_groh int not null primary key,
'parent nvarchar(50)null,
'child nvarchar(50)null,
'id_kala nvarchar(15) not null,
'sharh_kala nvarchar(100) not null
Dim SQL As String = "INSERT INTO tarif_groh_kala (id_groh, parent, child, id_kala, sharh_kala) VALUES ('@id_groh', '@parent', '@child', '@id_kala', '@sharh_kala')"
Dim myConn = New SqlConnection("Initial Catalog=Liste Outils;" & "Data Source=NOTEBOOK\TEW_SQLEXPRESS;Integrated Security=SSPI;")
'Open the connection.
myConn.Open()
Dim cmd As SqlCommand = New SqlCommand(SQL, myConn)
cmd.Parameters.Add("@id_groh", SqlDbType.Int)
cmd.Parameters.Add("@parent", SqlDbType.NVarChar)
cmd.Parameters.Add("@child", SqlDbType.NVarChar)
cmd.Parameters.Add("@id_kala", SqlDbType.NVarChar)
cmd.Parameters.Add("@sharh_kala", SqlDbType.NVarChar)
Call CallRecursive(TV)
Dim nodeNumber As Integer = 1
For Each node As TreeNode In TV.Nodes
Dim itemNumber As Integer = 0
For Each item As TreeNodeCollection In node.Nodes
cmd.Parameters("@id_groh").Value = nodeNumber + itemNumber
cmd.Parameters("@parent").Value = node.Parent.Name
cmd.Parameters("@child").Value = node.Name
cmd.Parameters("@id_kala").Value = item("id_kala").Name
cmd.Parameters("@sharh_kala").Value = item("sharh_kala").Name
cmd.ExecuteNonQuery()
itemNumber += 1
Next
nodeNumber += 1
Next node
cmd.Dispose()
myConn.Close()
myConn.Dispose()
End Sub |
Partager