IdentifiantMot de passe
Loading...
Mot de passe oublié ?Je m'inscris ! (gratuit)
Navigation

Inscrivez-vous gratuitement
pour pouvoir participer, suivre les réponses en temps réel, voter pour les messages, poser vos propres questions et recevoir la newsletter

C# Discussion :

Exception de conversion de type


Sujet :

C#

  1. #1
    Membre régulier
    Homme Profil pro
    Inscrit en
    Mai 2012
    Messages
    228
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : France

    Informations forums :
    Inscription : Mai 2012
    Messages : 228
    Points : 80
    Points
    80
    Par défaut Exception de conversion de type
    Bonjour à tous et toutes,
    Je met ci-joint mon programme qui génére une exeption et je ne sais pas pourquoi : Le format de la chaine entrée est incorrect. (Partie ma nutrition rechercher un aliment : quand on fait une recherche avec un = comme sodium = 15,5)
    Voici le code qui génére l'exception (dans user_control_nutrition)
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
     if (float.Parse(reader.GetString(this.comboBox_Categorie.SelectedIndex + 3).Replace(".", ",")) == float.Parse("" + textBox_Valeur.Text.Replace(".", "."))) { this.listView1.Items.AddRange(new ListViewItem[] { item }); }
    Merci d'avance...
    Fichiers attachés Fichiers attachés

  2. #2
    Membre expert
    Avatar de GuruuMeditation
    Homme Profil pro
    .Net Architect
    Inscrit en
    Octobre 2010
    Messages
    1 705
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Âge : 49
    Localisation : Belgique

    Informations professionnelles :
    Activité : .Net Architect
    Secteur : Conseil

    Informations forums :
    Inscription : Octobre 2010
    Messages : 1 705
    Points : 3 568
    Points
    3 568
    Par défaut
    "this.comboBox_Categorie.SelectedIndex + 3" me renvoie "cervelle, agneau,cuite". Ce qui ne peut pas être converti en float Par contre "this.comboBox_Categorie.SelectedIndex + 4" me renvoit bien un nombre (130). C'est probablement ça le problème
    Microsoft MVP : Windows Platform

    MCPD - Windows Phone Developer
    MCPD - Windows Developer 4

    http://www.guruumeditation.net

    “If debugging is the process of removing bugs, then programming must be the process of putting them in.”
    (Edsger W. Dijkstra)

  3. #3
    Membre régulier
    Homme Profil pro
    Inscrit en
    Mai 2012
    Messages
    228
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : France

    Informations forums :
    Inscription : Mai 2012
    Messages : 228
    Points : 80
    Points
    80
    Par défaut
    C'est bien vu, seulement ça ne marche toujours pas même après correction... Merci quand même

  4. #4
    Membre régulier
    Homme Profil pro
    Inscrit en
    Mai 2012
    Messages
    228
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : France

    Informations forums :
    Inscription : Mai 2012
    Messages : 228
    Points : 80
    Points
    80
    Par défaut
    Personne d'autre n'a une idée?

  5. #5
    Membre expert
    Avatar de GuruuMeditation
    Homme Profil pro
    .Net Architect
    Inscrit en
    Octobre 2010
    Messages
    1 705
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Âge : 49
    Localisation : Belgique

    Informations professionnelles :
    Activité : .Net Architect
    Secteur : Conseil

    Informations forums :
    Inscription : Octobre 2010
    Messages : 1 705
    Points : 3 568
    Points
    3 568
    Par défaut
    Je vois que reader.GetString(this.comboBox_Categorie.SelectedIndex + 4) renvoie à un moment "-". C'est ça qui bloque à la conversion.
    Microsoft MVP : Windows Platform

    MCPD - Windows Phone Developer
    MCPD - Windows Developer 4

    http://www.guruumeditation.net

    “If debugging is the process of removing bugs, then programming must be the process of putting them in.”
    (Edsger W. Dijkstra)

  6. #6
    Membre régulier
    Homme Profil pro
    Inscrit en
    Mai 2012
    Messages
    228
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : France

    Informations forums :
    Inscription : Mai 2012
    Messages : 228
    Points : 80
    Points
    80
    Par défaut
    Oui, mais les autres conversions sont elles bloqué? parce que chez moi oui... aucune conversion ne marche et toutes sans exceptions générent des exceptions...

  7. #7
    Membre expert
    Avatar de GuruuMeditation
    Homme Profil pro
    .Net Architect
    Inscrit en
    Octobre 2010
    Messages
    1 705
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Âge : 49
    Localisation : Belgique

    Informations professionnelles :
    Activité : .Net Architect
    Secteur : Conseil

    Informations forums :
    Inscription : Octobre 2010
    Messages : 1 705
    Points : 3 568
    Points
    3 568
    Par défaut
    Perso chez moi les conversions marchent. En tout cas si c'est juste un chiffre.
    Le "-" que j'ai eu qui faisait planter était sur la 4eme ou 5eme ligne. Pas de problèmes avec celles avant.
    Microsoft MVP : Windows Platform

    MCPD - Windows Phone Developer
    MCPD - Windows Developer 4

    http://www.guruumeditation.net

    “If debugging is the process of removing bugs, then programming must be the process of putting them in.”
    (Edsger W. Dijkstra)

  8. #8
    Membre régulier
    Homme Profil pro
    Inscrit en
    Mai 2012
    Messages
    228
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : France

    Informations forums :
    Inscription : Mai 2012
    Messages : 228
    Points : 80
    Points
    80
    Par défaut
    Ah c'est bizarre cela

  9. #9
    Membre expert
    Avatar de GuruuMeditation
    Homme Profil pro
    .Net Architect
    Inscrit en
    Octobre 2010
    Messages
    1 705
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Âge : 49
    Localisation : Belgique

    Informations professionnelles :
    Activité : .Net Architect
    Secteur : Conseil

    Informations forums :
    Inscription : Octobre 2010
    Messages : 1 705
    Points : 3 568
    Points
    3 568
    Par défaut
    J'essaye avec l’exemple que tu as donné. Sodium = 15.5
    Microsoft MVP : Windows Platform

    MCPD - Windows Phone Developer
    MCPD - Windows Developer 4

    http://www.guruumeditation.net

    “If debugging is the process of removing bugs, then programming must be the process of putting them in.”
    (Edsger W. Dijkstra)

  10. #10
    Membre régulier
    Homme Profil pro
    Inscrit en
    Mai 2012
    Messages
    228
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : France

    Informations forums :
    Inscription : Mai 2012
    Messages : 228
    Points : 80
    Points
    80
    Par défaut
    Edit 1 : ça marche ça y'est ! merci !

Discussions similaires

  1. Réponses: 2
    Dernier message: 30/05/2014, 14h45
  2. Réponses: 0
    Dernier message: 30/05/2014, 10h54
  3. Conversion de type
    Par poirier dans le forum ASP
    Réponses: 2
    Dernier message: 06/07/2004, 10h30
  4. [MYSQL] conversion de type sur import de script
    Par sebos63 dans le forum SQL Procédural
    Réponses: 2
    Dernier message: 27/08/2003, 10h00
  5. Réponses: 2
    Dernier message: 05/06/2002, 12h29

Partager

Partager
  • Envoyer la discussion sur Viadeo
  • Envoyer la discussion sur Twitter
  • Envoyer la discussion sur Google
  • Envoyer la discussion sur Facebook
  • Envoyer la discussion sur Digg
  • Envoyer la discussion sur Delicious
  • Envoyer la discussion sur MySpace
  • Envoyer la discussion sur Yahoo