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 :

probleme requête paramétrée


Sujet :

C#

  1. #1
    Membre du Club Avatar de zakaroh
    Inscrit en
    Avril 2008
    Messages
    129
    Détails du profil
    Informations forums :
    Inscription : Avril 2008
    Messages : 129
    Points : 48
    Points
    48
    Par défaut probleme requête paramétrée
    Bonjour,
    j'ai un problème avec une requête le code :


    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    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
     
     command.Parameters.Add(new SqlParameter("@ID_project", SqlDbType.NVarChar, 50));
     
                command.Parameters.Add(new SqlParameter("@Duration_Estimate_PH_0", SqlDbType.Float));
                command.Parameters.Add(new SqlParameter("@Duration_Estimate_PH_1", SqlDbType.Float));
                command.Parameters.Add(new SqlParameter("@Duration_Estimate_PH_2", SqlDbType.Float));
                command.Parameters.Add(new SqlParameter("@Duration_Estimate_PH_3", SqlDbType.Float));
                command.Parameters.Add(new SqlParameter("@Duration_Estimate_at_Completion", SqlDbType.Float));
                command.Parameters.Add(new SqlParameter("@ETM_PH_0_", SqlDbType.Float));
                command.Parameters.Add(new SqlParameter("@ETM_PH_1_", SqlDbType.Float));
                command.Parameters.Add(new SqlParameter("@ETM_PH_2_", SqlDbType.Float));
                command.Parameters.Add(new SqlParameter("@ETM_PH_3_", SqlDbType.Float));
     
     
                command.Parameters["@ID_project"].Value = textBox_project_name.Text;
                command.Parameters["@Duration_Estimate_PH_0"].Value = textBox_Duration_Estimate_PH_0.Text;
                command.Parameters["@Duration_Estimate_PH_1"].Value = textBox_Duration_Estimate_PH_1.Text;
                command.Parameters["@Duration_Estimate_PH_2"].Value = textBox_Duration_Estimate_PH_2.Text;
                command.Parameters["@Duration_Estimate_PH_3"].Value = textBox_Duration_Estimate_PH_3.Text;
                command.Parameters["@Duration_Estimate_at_Completion"].Value = textBox_Duration_Dstimate_at_Completion.Text;
                command.Parameters["@ETM_PH_0_"].Value = textBox_ETM_Phase_0.Text;
                command.Parameters["@ETM_PH_1_"].Value = textBox_ETM_Phase_1.Text;
                command.Parameters["@ETM_PH_2_"].Value = textBox_ETM_Phase_2.Text;
                command.Parameters["@ETM_PH_3_"].Value = textBox_ETM_Phase_3.Text;
     
                Convert.ToDouble(textBox_Duration_Estimate_PH_0.Text, CultureInfo.InvariantCulture);
                Convert.ToDouble(textBox_Duration_Estimate_PH_1.Text, CultureInfo.InvariantCulture);
                Convert.ToDouble(textBox_Duration_Estimate_PH_2.Text, CultureInfo.InvariantCulture);
                Convert.ToDouble(textBox_Duration_Estimate_PH_3.Text, CultureInfo.InvariantCulture);
                Convert.ToDouble(textBox_Duration_Dstimate_at_Completion.Text, CultureInfo.InvariantCulture);
                Convert.ToDouble(textBox_ETM_Phase_0.Text, CultureInfo.InvariantCulture);
                Convert.ToDouble(textBox_ETM_Phase_1.Text, CultureInfo.InvariantCulture);
                Convert.ToDouble(textBox_ETM_Phase_2.Text, CultureInfo.InvariantCulture);
                Convert.ToDouble(textBox_ETM_Phase_3.Text, CultureInfo.InvariantCulture);
     
                 command.ExecuteNonQuery();
    le message d'erreur est le suivant :

    Input string was not in a correct format : Convert.ToDouble(textBox_Duration_Estimate_PH_0.Text, CultureInfo.InvariantCulture);

    merci

  2. #2
    Rédacteur
    Avatar de SaumonAgile
    Homme Profil pro
    Team leader
    Inscrit en
    Avril 2007
    Messages
    4 028
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : France, Moselle (Lorraine)

    Informations professionnelles :
    Activité : Team leader
    Secteur : Conseil

    Informations forums :
    Inscription : Avril 2007
    Messages : 4 028
    Points : 6 334
    Points
    6 334
    Par défaut
    C'est sans doute lié au format du séparateur décimal, tu utilises le . ou la , ?
    Besoin d'un MessageBox amélioré ? InformationBox pour .NET 1.1, 2.0, 3.0, 3.5, 4.0 sous license Apache 2.0.

    Bonnes pratiques pour les accès aux données
    Débogage efficace en .NET
    LINQ to Objects : l'envers du décor

    Mon profil LinkedIn - MCT - MCPD WinForms - MCTS Applications Distribuées - MCTS WCF - MCTS WCF 4.0 - MCTS SQL Server 2008, Database Development - Mon blog - Twitter

  3. #3
    Membre du Club Avatar de zakaroh
    Inscrit en
    Avril 2008
    Messages
    129
    Détails du profil
    Informations forums :
    Inscription : Avril 2008
    Messages : 129
    Points : 48
    Points
    48
    Par défaut
    merci,
    tu utilises le . ou la ,
    je ne comprends pas ta question.

  4. #4
    Membre extrêmement actif Avatar de fally
    Homme Profil pro
    Développeur .Net / BI
    Inscrit en
    Novembre 2007
    Messages
    966
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : Bénin

    Informations professionnelles :
    Activité : Développeur .Net / BI

    Informations forums :
    Inscription : Novembre 2007
    Messages : 966
    Points : 1 173
    Points
    1 173
    Par défaut
    Il veut dire que c'est un problème de Culture

  5. #5
    Membre du Club Avatar de zakaroh
    Inscrit en
    Avril 2008
    Messages
    129
    Détails du profil
    Informations forums :
    Inscription : Avril 2008
    Messages : 129
    Points : 48
    Points
    48
    Par défaut
    avez vous une solution pour moi? je n arrive pas a résoudre ce problème.
    merci

  6. #6
    Membre confirmé Avatar de getz85
    Homme Profil pro
    Développeur informatique
    Inscrit en
    Janvier 2008
    Messages
    423
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Âge : 39
    Localisation : France, Loire Atlantique (Pays de la Loire)

    Informations professionnelles :
    Activité : Développeur informatique
    Secteur : High Tech - Multimédia et Internet

    Informations forums :
    Inscription : Janvier 2008
    Messages : 423
    Points : 462
    Points
    462
    Par défaut
    essaye au moins de chercher avec ce que l'on te dit..
    SaumonAgile voulait te dire que cela vient surement du séparateur de tes nombres décimaux, si ce sont des virgules essaye avec des points, et vice versa...

  7. #7
    Membre du Club Avatar de zakaroh
    Inscrit en
    Avril 2008
    Messages
    129
    Détails du profil
    Informations forums :
    Inscription : Avril 2008
    Messages : 129
    Points : 48
    Points
    48
    Par défaut
    pour le séparateur décimal j'utulse la vergule.

  8. #8
    Expert éminent sénior
    Avatar de Skyounet
    Homme Profil pro
    Software Engineer
    Inscrit en
    Mars 2005
    Messages
    6 380
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Âge : 37
    Localisation : Etats-Unis

    Informations professionnelles :
    Activité : Software Engineer
    Secteur : High Tech - Éditeur de logiciels

    Informations forums :
    Inscription : Mars 2005
    Messages : 6 380
    Points : 13 380
    Points
    13 380
    Par défaut
    De toute façon pour les Parameters il me semble que tu n'as pas besoin de convertir dans le type voulu, tu lui donnes un string et lui il se débrouille normalement non ?

    Dans le cas contraire
    http://www.developpez.net/forums/sho...hlight=virgule
    Introduction à Silverlight 4 (new) ; Localisation d'une application Silverlight (new) ;
    Mon espace perso[/B]

    La connaissance s’acquiert par l’expérience, tout le reste n’est que de l’information. Albert Einstein[/SIZE]

  9. #9
    Membre extrêmement actif Avatar de fally
    Homme Profil pro
    Développeur .Net / BI
    Inscrit en
    Novembre 2007
    Messages
    966
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : Bénin

    Informations professionnelles :
    Activité : Développeur .Net / BI

    Informations forums :
    Inscription : Novembre 2007
    Messages : 966
    Points : 1 173
    Points
    1 173
    Par défaut
    Citation Envoyé par Skyounet Voir le message
    De toute façon pour les Parameters il me semble que tu n'as pas besoin de convertir dans le type voulu, tu lui donnes un string et lui il se débrouille normalement non ?
    NON, il FAUT convertir dans le type qui est dans la base ou le type du paramètre

  10. #10
    Expert éminent sénior
    Avatar de Skyounet
    Homme Profil pro
    Software Engineer
    Inscrit en
    Mars 2005
    Messages
    6 380
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Âge : 37
    Localisation : Etats-Unis

    Informations professionnelles :
    Activité : Software Engineer
    Secteur : High Tech - Éditeur de logiciels

    Informations forums :
    Inscription : Mars 2005
    Messages : 6 380
    Points : 13 380
    Points
    13 380
    Par défaut
    Citation Envoyé par fally Voir le message
    NON, il FAUT convertir dans le type qui est dans la base ou le type du paramètre
    En fait pour avoir cette abstraction du type il ne faut pas spécifier le DbType en créant son paramètre.

    Exemple avec Northwind

    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    SqlCommand command = new SqlCommand();
    command.CommandText = "INSERT INTO Products(ProductName, UnitPrice, UnitsInStock) VALUES (@p1, @p2, @p3)";
     
    command.Parameters.AddWithValue("@p1", "test");
    command.Parameters.AddWithValue("@p2", "45.4");
    command.Parameters.AddWithValue("@p3", "4");
    Ca fonctionne très bien malgré le fait que p2 et p3 sont censés être des Money et des SmallInt.
    Introduction à Silverlight 4 (new) ; Localisation d'une application Silverlight (new) ;
    Mon espace perso[/B]

    La connaissance s’acquiert par l’expérience, tout le reste n’est que de l’information. Albert Einstein[/SIZE]

  11. #11
    Membre du Club Avatar de zakaroh
    Inscrit en
    Avril 2008
    Messages
    129
    Détails du profil
    Informations forums :
    Inscription : Avril 2008
    Messages : 129
    Points : 48
    Points
    48
    Par défaut
    merci pour tout,
    j'ai fais ce code
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    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
     
     {
               // Chaîne de connexion
                string connectString = @"Data Source=RENNDXPRDL2596\SQLEXPRESS;Initial Catalog=hafid;Integrated Security=True";
                // Objet connection
                SqlConnection connection = new SqlConnection(connectString);
                // Ouverture
                connection.Open();
     
     
                SqlCommand command = new SqlCommand();
     
                   command.CommandText = "INSERT INTO [table_PPA]([ID_project],[Duration_Estimate_PH_0],[Duration_Estimate_PH_1],[Duration_Estimate_PH_2],[Duration_Estimate_PH_3],[Duration_Estimate_at_Completion],[ETM_PH_0_],[ETM_PH_1_],[ETM_PH_2_],[ETM_PH_3_]) VALUES(@ID_project,@Duration_Estimate_PH_0,@Duration_Estimate_PH_1,@Duration_Estimate_PH_2,@Duration_Estimate_PH_3,@Duration_Estimate_at_Completion,@ETM_PH_0_,@ETM_PH_1_,@ETM_PH_2_,@ETM_PH_3_)";
     
                // Paramètres
     
     
     
                command.Parameters.AddWithValue("@ID_project","textBox_project_name.Text");
     
                command.Parameters.AddWithValue("@Duration_Estimate_PH_0","textBox_Duration_Estimate_PH_0.Text");
                command.Parameters.AddWithValue("@Duration_Estimate_PH_1","textBox_Duration_Estimate_PH_1.Text");
                command.Parameters.AddWithValue("@Duration_Estimate_PH_2","textBox_Duration_Estimate_PH_2.Text");
                command.Parameters.AddWithValue("@Duration_Estimate_PH_3","textBox_Duration_Estimate_PH_3");
                command.Parameters.AddWithValue("@Duration_Estimate_at_Completion","textBox_Duration_Dstimate_at_Completion.Text");
                command.Parameters.AddWithValue("@ETM_PH_0_","textBox_ETM_Phase_0.Text");
                command.Parameters.AddWithValue("@ETM_PH_1_","textBox_ETM_Phase_1.Text");
                command.Parameters.AddWithValue("@ETM_PH_2_","Value = textBox_ETM_Phase_2.Text");
                command.Parameters.AddWithValue("@ETM_PH_3_","textBox_ETM_Phase_3.Text");
     
     
                 command.ExecuteNonQuery();
     
            }
    ca bug et j'ai ce message

    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
     
    ExecuteNonQuery: Connection property has not been initialized.

  12. #12
    Expert éminent sénior
    Avatar de Skyounet
    Homme Profil pro
    Software Engineer
    Inscrit en
    Mars 2005
    Messages
    6 380
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Âge : 37
    Localisation : Etats-Unis

    Informations professionnelles :
    Activité : Software Engineer
    Secteur : High Tech - Éditeur de logiciels

    Informations forums :
    Inscription : Mars 2005
    Messages : 6 380
    Points : 13 380
    Points
    13 380
    Par défaut
    Tu n'as pas associé ta connexion à ta commande.

    command.Connection = connection;
    Introduction à Silverlight 4 (new) ; Localisation d'une application Silverlight (new) ;
    Mon espace perso[/B]

    La connaissance s’acquiert par l’expérience, tout le reste n’est que de l’information. Albert Einstein[/SIZE]

  13. #13
    Membre émérite Avatar de Guulh
    Homme Profil pro
    Inscrit en
    Septembre 2007
    Messages
    2 160
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Âge : 42
    Localisation : France, Paris (Île de France)

    Informations forums :
    Inscription : Septembre 2007
    Messages : 2 160
    Points : 2 925
    Points
    2 925
    Par défaut
    Ou mieux :
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    SqlCommand command = connection.CreateCommand();
    ಠ_ಠ

  14. #14
    Membre extrêmement actif Avatar de fally
    Homme Profil pro
    Développeur .Net / BI
    Inscrit en
    Novembre 2007
    Messages
    966
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : Bénin

    Informations professionnelles :
    Activité : Développeur .Net / BI

    Informations forums :
    Inscription : Novembre 2007
    Messages : 966
    Points : 1 173
    Points
    1 173
    Par défaut
    Citation Envoyé par Skyounet Voir le message
    En fait pour avoir cette abstraction du type il ne faut pas spécifier le DbType en créant son paramètre.
    Merci pour l'info, mais je teste d'abord

Discussions similaires

  1. Réponses: 1
    Dernier message: 29/07/2014, 08h33
  2. [VB.NET] [ADO.NET] Requête paramétrée
    Par DotNET74 dans le forum Accès aux données
    Réponses: 2
    Dernier message: 11/03/2005, 08h39
  3. probleme requête insert.... where
    Par Amandine62 dans le forum Langage SQL
    Réponses: 7
    Dernier message: 21/02/2005, 14h26
  4. Requête paramétrée qui remplit une DBLookUpComboBox
    Par navis84 dans le forum Bases de données
    Réponses: 6
    Dernier message: 02/12/2004, 21h23
  5. VBA & Requête paramétrée
    Par gripoil dans le forum Access
    Réponses: 4
    Dernier message: 25/11/2004, 09h54

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