Hye dude,

Really need help. My problem is I want to insert data from treeview checkboxes into database. Currently im using an array, but when i insert the value it become double. for example, when i click two checkbox. the id insert in database will be two. Can someone help me? since i'm a newbie in vb programming.. sory for bad english.

Private Sub Button1_Click(sender As System.Object, e As System.EventArgs) Handles Button1.Click
        Dim s As String = ""
        Dim bool As Integer
        con.Open()
        cmd.Connection = con
        For Each n As TreeNode In GetCheck(TreeView1.Nodes)
            If n.Text = "Can Add" and n.Checked = True Then 
                s = n.Name
                bool = 1

            End If
            If n.Text = "Can Edit" And n.Checked = True Then
                s = n.Name
                bool = 0
            End If
            cmd.CommandText = "Insert into subtreeright (FormName, CanDelete, CanEdit) " & _
                 " Values ('" & s.ToString & "', '" & bool.ToString & "', '" & bool.ToString & "')"
            cmd.ExecuteNonQuery()
        Next

        MsgBox("New User Saved!")
        con.Close()

    End Sub

you are trying to insert two values (canAdd and canEdit) in a single row, but treeview will loop twice for two checkboxes , plus your insert statement is inside the loop hence two entries

By the way what does getcheck function do here ?

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.