deux combobox dans une même form VB.NET ACCESS
Bonjour,
merci de m'aider pour resoudre mon probleme:
mon probleme consiste à remplir deux combobox chacun provient d'une table independant pour ajouté un nouveau enregistrement produit
combobox1; provient de la table categorie et m'affiche dans un textbox le libellé categorie produit
Combobox2:provient de la table fournisseur et m'affiche dans un textbox le fournisseur de produit
code de form load:
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
| Private Sub Ajouter_Produit_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
'Categories
Try
Dim dr As OleDbDataReader
CN.Open()
cmd.Connection = CN
cmd.CommandText = "select * from Categories "
dr = cmd.ExecuteReader
Remplir_Liste_Produits()
While dr.Read
ComboBox1.Items.Add(dr.GetValue(0).ToString)
End While
CN.Close()
Catch ex As Exception
End Try
'Fournisseurs
Try
Dim dr1 As OleDbDataReader
CN.Open()
cmd1.Connection = CN
cmd1.CommandText = "select * from Fournisseurs "
dr1 = cmd.ExecuteReader
Remplir_Liste_Produits()
While dr1.Read
ComboBox2.Items.Add(dr1.GetValue(1))
End While
CN.Close()
Catch ex As Exception
End Try
End Sub |
et sa c'est le code de bouton ajouter:
Code:
1 2 3 4 5 6 7 8 9 10 11 12 13 14
| Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click, Button4.Click
Try
CN.Open()
cmd5.Connection = CN
Dim dr5 As OleDbDataReader
cmd5.CommandText = "insert into Produits values('" & TextBox1.Text & "','" & TextBox2.Text & "','" & TextBox3.Text & "','" & TextBox4.Text & "','" & TextBox5.Text & "','" & TextBox6.Text & "','" & TextBox7.Text & "','" & TextBox8.Text & "','" & TextBox9.Text & "','" & TextBox10.Text & "','" & DateTimePicker1.Text & "','" & ComboBox1.Text & "','" & ComboBox2.Text & "')"
dr5 = cmd5.ExecuteReader
MsgBox("Enregistré avec succée")
CN.Close()
Catch ex As Exception
End Try
End Sub |
Merci
1 pièce(s) jointe(s)
comment remplir deux combobox de deux tables differents dans le même form vb.net access
Merci pour votre remarque mais lorsque j'ai rectifier comme vous m'avez dit le même probleme j'ai reçu
Code:
ComboBox2.Items.Add(dr1.GetValue(0))
le combobox2 à prix celui de combobox1
Code:
ComboBox1.Items.Add(dr1.GetValue(0))
S'il vous plait aidez moi
comment remplir deux combobox de deux tables differents dans le même form vb.net access
le probleme que pour combobox2 ne prend pas les informations de la requete
Code:
select * from Fournisseurs
le code de bouton enregistrer :
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, Button4.Click
Try
CN.Open()
cmd5.Connection = CN
Dim dr5 As OleDbDataReader
cmd5.CommandText = "insert into Produits values('" & TextBox1.Text & "','" & TextBox2.Text & "','" & TextBox3.Text & "','" & TextBox4.Text & "','" & TextBox5.Text & "','" & TextBox6.Text & "','" & TextBox7.Text & "','" & TextBox8.Text & "','" & TextBox9.Text & "','" & TextBox10.Text & "','" & DateTimePicker1.Text & "','" & ComboBox1.Text & "','" & ComboBox2.Text & "')"
dr5 = cmd5.ExecuteReader
MsgBox("Enregistré avec succée")
TextBox1.Enabled = False
TextBox2.Enabled = False
TextBox3.Enabled = False
TextBox4.Enabled = False
TextBox5.Enabled = False
TextBox7.Enabled = False
TextBox8.Enabled = False
TextBox9.Enabled = False
TextBox10.Enabled = False
ComboBox1.Enabled = False
ComboBox1.Enabled = False
DateTimePicker1.Enabled = False
TextBox1.Text = ""
TextBox2.Text = ""
TextBox3.Text = ""
TextBox4.Text = ""
TextBox5.Text = ""
TextBox6.Text = ""
TextBox7.Text = ""
TextBox8.Text = ""
TextBox9.Text = ""
TextBox10.Text = ""
ComboBox1.Text = ""
ComboBox2.Text = ""
DateTimePicker1.Text = Now
CN.Close()
Catch ex As Exception
End Try
End Sub |