<pre> Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
Try
DateTimePicker1.Value = Date.Now
Dim cmd As OleDbCommand = New OleDbCommand("select * from dossier_ass where pieces_fourni =@pieces_fourni and pieces_manquant = @pieces_manquant", cn)
Dim da As New OleDbDataAdapter(cmd)
Dim dt As New DataTable()
Dim pieces_fourni As String = ""
Dim pieces_manquant As String = ""
cmd.Parameters.AddWithValue("@pieces_fourni", pieces_fourni)
cmd.Parameters.AddWithValue("@pieces_manquant", pieces_manquant)
cn.Open()
cmd = New OleDbCommand("Insert into tab_asso (id_dossier,denomination,date_recep,nom_prenom,adresse,wilaya,code_wilaya,region,pieces_fourni,pieces_manquant) VALUES(@id_dossier,@denomination,@date_recep,@nom_prenom,@adresse,@wilaya,@code_wilaya,@region,@pieces_fourni,@pieces_manquant) ", cn)
cmd.Parameters.AddWithValue("@id_dossier", TextBox1.Text)
cmd.Parameters.AddWithValue("@denomination", TextBox2.Text)
cmd.Parameters.AddWithValue("@date_recep", DateTimePicker1.Text)
cmd.Parameters.AddWithValue("@nom_prenom", TextBox6.Text)
cmd.Parameters.AddWithValue("@adresse", TextBox7.Text)
cmd.Parameters.AddWithValue("@wilaya", ComboBox1.Text)
cmd.Parameters.AddWithValue("@code_wilaya", TextBox4.Text)
cmd.Parameters.AddWithValue("@Region", TextBox5.Text)
For Each dr As DataRow In dt.Rows
Dim selectedIndex As Integer = CheckedListBox1.SelectedIndex
If selectedIndex <> -1 Then
For i As Integer = 0 To CheckedListBox1.Items.Count - 1
Dim checkstate As CheckState
checkstate = CheckedListBox1.GetItemCheckState(i)
If (checkstate = checkstate.Checked) Then
cmd.Parameters.AddWithValue("@pieces_fourni", CheckedListBox1.Items(i)).ToString()
Else
cmd.Parameters.AddWithValue("@pieces_manquant", CheckedListBox1.Items(i)).ToString()
End If
Next
End If
Next
cmd.ExecuteNonQuery()
Catch ex As Exception
MessageBox.Show("Erreur lors de l'insertion de l'enregistrement dans la table..." & ex.Message, "Insértion d'Enregistrement")
Finally
cn.Close()
refraiche()
End Try
MessageBox.Show("Données insérées avec succès")
End Sub
What I have tried:
Hello everybody
I have a CheckedListBox which designates the file documents to be provided I want the checked boxes to be stored in a single field named pieces_fourni in my access table and the unchecked boxes to be stored in another single field named pieces_manquant I have tried several times without success, Can anybody help me here is the code