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

Windows Forms Discussion :

Problème avec DbDataReader


Sujet :

Windows Forms

Vue hybride

Message précédent Message précédent   Message suivant Message suivant
  1. #1
    Membre confirmé
    Profil pro
    Inscrit en
    Juin 2007
    Messages
    143
    Détails du profil
    Informations personnelles :
    Localisation : Belgique

    Informations forums :
    Inscription : Juin 2007
    Messages : 143
    Par défaut Problème avec DbDataReader
    Voilà le code :
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
     commande.Parameters["@per_nom"].Value = Nom;
    commande.Parameters["@per_prenom"].Value = Prenom;
    commande.Parameters["@per_email"].Value = Mail;
    DbDataReader r = commande.ExecuteReader();
    r.Read();
    return r.GetInt32(1);
    Le problème survint au moment de return, le programme n'a pas l'air de me retourner un int.
    Merci d'avance.

  2. #2
    Rédacteur
    Avatar de Thomas Lebrun
    Profil pro
    Inscrit en
    Octobre 2002
    Messages
    9 161
    Détails du profil
    Informations personnelles :
    Âge : 43
    Localisation : France

    Informations forums :
    Inscription : Octobre 2002
    Messages : 9 161
    Par défaut
    Bon, avec le peu d'informations que tu donnes, c'est pas évident de tout suivre mais je suppose que l'entier que tu voudrais récupérer, c'est l'identifiant, c'est bien cela ?

    As-tu essayé: return r.GetInt32(0); ?

  3. #3
    Membre confirmé
    Profil pro
    Inscrit en
    Juin 2007
    Messages
    143
    Détails du profil
    Informations personnelles :
    Localisation : Belgique

    Informations forums :
    Inscription : Juin 2007
    Messages : 143
    Par défaut
    Vous voulez quoi comme information? Oui c'est avec 0 que j'avais mis, je me suis trompé en recopiant.

  4. #4
    Membre confirmé
    Profil pro
    Inscrit en
    Juin 2007
    Messages
    143
    Détails du profil
    Informations personnelles :
    Localisation : Belgique

    Informations forums :
    Inscription : Juin 2007
    Messages : 143
    Par défaut
    En voilà + :

    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
    37
    38
    39
    40
    41
    42
    43
    44
    45
    46
    47
    48
    49
    50
    51
    52
    53
    54
     static public void CréerCompte(PerComplet p)
            {
                DbConnection connection = UsineCommande.Usine.Con;
                DbCommand commande1 = UsineCommande.Usine.CreerComptePER;
                DbCommand commande2 = UsineCommande.Usine.CreerCompteAPP;
     
                connection.Open();
                try
                {
                    commande1.Parameters["@per_nom"].Value = p.Nom;
                    commande1.Parameters["@per_prenom"].Value = p.Prenom;
                    commande1.Parameters["@per_mdp"].Value = p.MDP;
                    commande1.Parameters["@per_email"].Value = p.Mail;
                    commande1.Parameters["@per_organisateur"].Value = p.Organisateur;
                    commande2.Parameters["@app_fk_gro"].Value = p.Idgroupe;
     
                    int Id = ChercherIdPER(p.Nom, p.Prenom, p.Mail);
     
                    commande2.Parameters["@app_fk_per"].Value = Id;
     
                    if (commande1.ExecuteNonQuery() == 0 || commande2.ExecuteNonQuery() == 0)
                        throw new Exception("Echec d'insertion.");
     
                }
                catch (Exception e)
                {
                    throw UsineException.ObtenirException(e.Message);
                }
                finally
                {
                    connection.Close();
                }
            }
     
            static public int ChercherIdPER(String Nom, String Prenom, String Mail)
            {
                DbCommand commande = UsineCommande.Usine.ChercherIdPER;
     
                try
                {
                    commande.Parameters["@per_nom"].Value = Nom;
                    commande.Parameters["@per_prenom"].Value = Prenom;
                    commande.Parameters["@per_email"].Value = Mail;
                    DbDataReader r = commande.ExecuteReader();
                    r.Read();
                    return r.GetInt32(1);
     
                }
     
                catch
                {
                    throw new Exception("Erreur lors de la recherche de l'identifiant");
                }
            }

  5. #5
    Membre confirmé
    Profil pro
    Inscrit en
    Juin 2007
    Messages
    143
    Détails du profil
    Informations personnelles :
    Localisation : Belgique

    Informations forums :
    Inscription : Juin 2007
    Messages : 143
    Par défaut
    Je dois peut-être utilisé autre chose que GetInt32(0)
    du return r.GetInt32(0);
    ?

  6. #6
    Membre confirmé
    Profil pro
    Inscrit en
    Juin 2007
    Messages
    143
    Détails du profil
    Informations personnelles :
    Localisation : Belgique

    Informations forums :
    Inscription : Juin 2007
    Messages : 143
    Par défaut
    J'ai changé mon code et le message d'erreur est "Un DataReader associé à cette commande est déjà ouvert. Il doit d'abord être fermé.":

    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
     static public void CréerCompte(PerComplet p)
            {
                DbConnection connection = UsineCommande.Usine.Con;
                DbCommand commande1 = UsineCommande.Usine.CreerComptePER;
                DbCommand commande2 = UsineCommande.Usine.CreerCompteAPP;
                DbCommand commande3 = UsineCommande.Usine.ChercherIdPER;
     
                connection.Open();
                try
                {
                    commande1.Parameters["@per_nom"].Value = p.Nom;
                    commande1.Parameters["@per_prenom"].Value = p.Prenom;
                    commande1.Parameters["@per_mdp"].Value = p.MDP;
                    commande1.Parameters["@per_email"].Value = p.Mail;
                    commande1.Parameters["@per_organisateur"].Value = p.Organisateur;
                    commande2.Parameters["@app_fk_gro"].Value = p.Idgroupe;
                    commande3.Parameters[0].Value = p.Nom;
                    commande3.Parameters[1].Value = p.Prenom;
                    commande3.Parameters[2].Value = p.Mail;
                    DbDataReader id = commande3.ExecuteReader();
                    id.Read();
                    commande2.Parameters["@app_fk_per"].Value = id;
     
                    if (commande1.ExecuteNonQuery() == 0 || commande2.ExecuteNonQuery() == 0)
                        throw new Exception("Echec d'insertion.");
     
                }
                catch (Exception e)
                {
                    throw UsineException.ObtenirException(e.Message);
                }
                finally
                {
                    connection.Close();
                }
            }

+ Répondre à la discussion
Cette discussion est résolue.

Discussions similaires

  1. Urgent : Encore un problème avec un DbDataReader
    Par Nadiya dans le forum Windows Forms
    Réponses: 6
    Dernier message: 11/06/2007, 09h03
  2. VC++ Direct3D8, problème avec LPD3DXFONT et LPD3DTEXTURE8
    Par Magus (Dave) dans le forum DirectX
    Réponses: 3
    Dernier message: 03/08/2002, 11h10
  3. Problème avec le type 'Corba::Any_out'
    Par Steven dans le forum CORBA
    Réponses: 2
    Dernier message: 14/07/2002, 18h48
  4. Problème avec la mémoire virtuelle
    Par Anonymous dans le forum CORBA
    Réponses: 13
    Dernier message: 16/04/2002, 16h10

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