Aide sur Combobox

Résolu
cs_SEB73460 Messages postés 271 Date d'inscription vendredi 15 avril 2005 Statut Membre Dernière intervention 29 novembre 2022 - 28 juin 2007 à 08:43
jbprogram Messages postés 30 Date d'inscription mardi 3 octobre 2006 Statut Membre Dernière intervention 11 mai 2011 - 27 déc. 2012 à 14:37
Bonjour,

Voila, apres avoir recuperer un champ de ma base access dans mon combobox je voudrai afficher un autre champ dans un textbox par rapport à la sélection de mon combobox

J'ai le message d'erreur suivant :
L'exception System.InvalidCastException n'a pas été gérée
  Message="Impossible d'effectuer un cast d'un objet de type 'System.String' en type 'System.Windows.Forms.TextBox'."
 
Si quelqu'un peux m'aider merci beaucoup

Voici mon code :

Private

Sub ComboBox1_SelectedIndexChanged(
ByVal sender
As System.Object,
ByVal e
As System.EventArgs)
Handles ComboBox1.SelectedIndexChanged

Dim MyConnexion
As OleDbConnection =
New OleDbConnection(
"Provider=Microsoft.Jet.OLEDB.4.0;Data source=" & Application.StartupPath &
"\PROG.mdb;")

Dim Mycommand As OleDbCommand MyConnexion.CreateCommand()Mycommand.CommandText

"SELECT * FROM PROG WHERE D‚signation = '" & ComboBox1.Text &
"'"MyConnexion.Open()

Dim myReader
As OleDbDataReader = Mycommand.ExecuteReader()myReader.Read()

If myReader.HasRows
ThenTextBox1 = myReader(

"Fabricant")

End
If

myReader.Close()MyConnexion.Close()

End
Sub

 

3 réponses

jrivet Messages postés 7392 Date d'inscription mercredi 23 avril 2003 Statut Membre Dernière intervention 6 avril 2012 60
28 juin 2007 à 08:53
Salut,
Sur quelle ligne survient l'erreur????

En .NET il n'y a plus de propriété par défaut.
Ce qui veux dire que si tu met TextBox1 = cela ne veut plus dire comme avant forcément TextBox1.Text.
Il faut préciser chaque propriété que tu veux affecter.
Donc il te faut si veux modifier le Text de ton TextBox TOUJOURS préciser.
TextBox1.Text

@+: Ju£i?n
Pensez: Réponse acceptée
3
cs_chimi Messages postés 20 Date d'inscription mardi 4 avril 2006 Statut Membre Dernière intervention 21 avril 2008
28 juin 2007 à 13:13
ton erreur est ici

if
myReader.HasRows

Then

TextBox1 = myReader(




"Fabricant"
)

End
If
fait ca

if
myReader.HasRows

Then

TextBox1. text = myReader(




"Fabricant"
)

End
If
0
jbprogram Messages postés 30 Date d'inscription mardi 3 octobre 2006 Statut Membre Dernière intervention 11 mai 2011
27 déc. 2012 à 14:37
Je suis très fanatique de Les bases de la gestion de fichiersLundi 18 mars 2003&
0
Rejoignez-nous