nouna1551
Messages postés10Date d'inscriptiondimanche 4 janvier 2009StatutMembreDernière intervention21 mars 2010
-
23 mai 2009 à 22:00
elmeksaoui1 -
5 août 2015 à 16:26
bonjour tt le monde,j'ai un peit probleme,je suis entraine de crrer une form dans laquelle j'ai une combobox et une datagridview la basse de donnes contient quatre table ja doit choisir un Athlete dans la combobx et les cordonnes d'entrainement vont etre affiche dans la datagridview
voila le code avec lme quelle j'ai travaillé mais il me donne une erreur
**************************
Imports System.Data.SqlClient
Public Class Form1
Dim con As SqlConnection
Dim cmd1, cmd2 As SqlCommand
Dim da, da2 As SqlDataAdapter
Dim ds As New DataSet
Dim dt, dt1 As DataTable
'*********************
Private Sub ComboBox1_SelectedIndexChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ComboBox1.SelectedIndexChanged
End Sub
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
con = New SqlConnection
con.ConnectionString = "Data Source=poste-92frh1132\SQLEXPRESS;integrated security=sspi;initial catalog=Athlete"
cmd1 = New SqlCommand
cmd1.CommandText = "select * from athlete"
con.CreateCommand()
con.Open()
cmd1.Connection = con
da = New SqlDataAdapter(cmd1)
da.Fill(ds, "Athlete")
dt = ds.Tables("athlete")
ComboBox1.DataSource = dt
ComboBox1.DisplayMember = "NomAthlete"
ComboBox1.ValueMember = "NumLicence"
cmd2 = New SqlCommand
cmd2.CommandText = "select * from Plan_Entrainement where NumLicence=" & ComboBox1.SelectedValue
con.CreateCommand()
cmd2.Connection = con
da2 = New SqlDataAdapter(cmd2)
da2.Fill(ds, "Plan_Entrainement")
dt1 = ds.Tables("Plan_Entrainement")
DataGridView1.DataSource = dt1
con.Close()
End Sub
End Class
je suis vraiment nesion de votre aide et merci d'avance
Mayzz
Messages postés2813Date d'inscriptionmardi 15 avril 2003StatutMembreDernière intervention 2 juin 202028 23 mai 2009 à 22:14
Bonsoir,
Quel type d'erreur rencontre tu ?
ComboBox1.DataSource = dt
ComboBox1.DisplayMember = "NomAthlete"
ComboBox1.ValueMember = "NumLicence"
cmd2 = New SqlCommand
'Le comboBox est rempli mais comme l'événement se déroule dans le Form_Load, il ne doit pas avoir été initialisé du coup place ces lignes
If ComboBox1.Items.Count > 0 then
ComboBox1.SelectedIndex = 0
Else
MsgBox ("Table vide !")
Return
End If
cmd2.CommandText = "select * from Plan_Entrainement where NumLicence=" & ComboBox1.SelectedValue
con.CreateCommand()
Commence déja par cela puis en suite si ca ne fonctionne toujours pas dis en plus su ton message d'erreur..
nouna1551
Messages postés10Date d'inscriptiondimanche 4 janvier 2009StatutMembreDernière intervention21 mars 2010 23 mai 2009 à 22:44
bon monsieur voila l'erreur[ L'opérateur '&' n'est pas défini pour chaîne "select * from Plan_Entrainement " et type 'DataRowView'.]
le debogage commene dans l'instruction
cmd2.CommandText =
"select * from Plan_Entrainement where Plan_Entrainement.NumLicence='" &
Me.ComboBox1.SelectedItem &
"'"
omarlward
Messages postés5Date d'inscriptionsamedi 4 novembre 2006StatutMembreDernière intervention25 mai 2009 24 mai 2009 à 16:49
c'est normale car aucun élément n'est selectionné dans le combo N° 1.
donc tu derva mettre la deuxieme requéte dans l'evenement seletedindex_changed du combo N°1:
Private Sub ComboBox1_SelectedIndexChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ComboBox1.SelectedIndexChanged
If ComboBox1.SelectedIndex > -1 then
cmd2 = New SqlCommand
cmd2.CommandText = "select * from Plan_Entrainement where NumLicence=" & ComboBox1.SelectedValue
con.CreateCommand()
cmd2.Connection = con
da2 = New SqlDataAdapter(cmd2)
da2.Fill(ds, "Plan_Entrainement")
dt1 = ds.Tables("Plan_Entrainement")
DataGridView1.DataSource = dt1
End If
End Sub
ennaim omar
Vous n’avez pas trouvé la réponse que vous recherchez ?
nouna1551
Messages postés10Date d'inscriptiondimanche 4 janvier 2009StatutMembreDernière intervention21 mars 2010 24 mai 2009 à 20:08
dsl monsieur mais le code que vous m'avez donner ne marche pas je l'ai deja utilisé .l'erreur c'est
[L'opérateur '&' n'est pas défini pour chaîne "select * from Plan_Entrainement " et type 'DataRowView'.]
Bonjour,
tester ce code ca va repondre a ton porbleme.
Private Sub ComboBox1_SelectedIndexChanged(ByVal sender As
If IsNumeric(ComboBox1.SelectedValue) then
cmd2 = New SqlCommand
cmd2.CommandText = "select * from Plan_Entrainement where NumLicence=" & ComboBox1.SelectedValue
con.CreateCommand()
cmd2.Connection = con
da2 = New SqlDataAdapter(cmd2)
da2.Fill(ds, "Plan_Entrainement")
dt1 = ds.Tables("Plan_Entrainement")
DataGridView1.DataSource = dt1
End If
End Sub