chargement de données dans un combobox
salut les pro.
j'ai un combobox chargé d'une source de données.Quand je sélectionne un item de ce combobox et je clique sur le bouton d'enregistrement le combobox sera vide,ce qui m'empèche à refaire la tache une autre fois.
comment je peux garder le combobox chargé de données?
voila le code que j'utilise pour le bouton d'enregistrement.
Code:
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
| Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click
Dim strsql As String = "Select * from responsable"
Dim strConnexion As String = "Persist Security Info=true;Integrated Security=SSPI;database=parc municipal;server=USER-PC\AHMED"
Dim x As Exception
Try
Dim oConnection As New SqlConnection(strConnexion)
oConnection.Open()
Dim ObjetDA As New SqlDataAdapter(strsql, oConnection)
ObjetDA.Fill(Parc_municipalDataSet1, "concerner_r")
ObjetDA.InsertCommand = New SqlCommand("INSERT INTO concerner_r (ID_resp,ID_cat) Values(@ID_resp,@ID_cat)", oConnection)
ObjetDA.InsertCommand.Parameters.Add("@ID_resp", SqlDbType.Int, 15, "ID_resp")
ObjetDA.InsertCommand.Parameters.Add("@ID_cat", SqlDbType.Int, 15, "ID_cat")
Dim DR As DataRow
DR = Parc_municipalDataSet1.Tables("concerner_r").NewRow
Dim cmd As New SqlCommand
Dim a As Integer
cmd.CommandType = CommandType.Text
cmd.CommandText = "select ID_resp from responsable where num_matricule='" & CInt(TextBox1.Text) & "';"
cmd.Connection = oConnection
a = cmd.ExecuteScalar()
DR("ID_resp") = a
DR("ID_cat") = ComboBox1.SelectedValue
Parc_municipalDataSet1.Tables("concerner_r").Rows.Add(DR)
ObjetDA.Update(Parc_municipalDataSet1, "concerner_r")
Parc_municipalDataSet1.Clear()
ObjetDA.Fill(Parc_municipalDataSet1, "concerner_r")
oConnection.Close()
Catch x
MsgBox("L'erreur suivante a été rencontrée :" & x.Message)
End Try
End Sub |
merci bien :)