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

ASP.NET Discussion :

Mini Problème d'écriture dans la base de donnée


Sujet :

ASP.NET

  1. #1
    Membre confirmé Avatar de DaisyVIP
    Profil pro
    Inscrit en
    Mai 2007
    Messages
    160
    Détails du profil
    Informations personnelles :
    Âge : 38
    Localisation : France, Gard (Languedoc Roussillon)

    Informations forums :
    Inscription : Mai 2007
    Messages : 160
    Par défaut Mini Problème d'écriture dans la base de donnée
    Bonjour, j'ai un problème avec ma connexion à ma base de donnée. alors voici mon code, et le problème que j'arrive à écrire dans ma base de donnée, mais seulement la deuxième ligne apparait dans ma BDD, pas la première, pourquoi? Il y a t'il quelque chose à écrire en plus???
    Merci de votre aide par avance.

    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
    protected void Button1_Click(object sender, EventArgs e)
        {
            string MyConstring = "Data Source=PROD005\\SQLEXPRESS;uid=PROD005\\hautot-daisy;pwd=uniqu;Initial Catalog='C:\\DOCUMENTS AND SETTINGS\\HAUTOT-DAISY\\MES DOCUMENTS\\STAGE_PROJET.MDF';Integrated Security=True";
     
            SqlConnection con = new SqlConnection(MyConstring);
     
            try
            {
                con.Open();
                SqlCommand MyCommand = new SqlCommand();
                MyCommand.Connection = con;
     
                MyCommand.CommandText = "INSERT INTO Etudier(code_course_content, course_content, code_group, code_course) values ('BO:25/08/92','" + txtContent1.Text + "','IG1','3')";
                MyCommand.CommandText = "INSERT INTO Observation(date, obs_day, code_group) values ('29/05/07','" + txtObs.Text + "','IG1')";
                //SqlDataReader MyDataReader;
                //MyDataReader = 
                MyCommand.ExecuteReader();
     
                /*while (MyDataReader.Read())
                {
                    ListBox1.Text = MyDataReader.GetString(1);
                } */
                con.Close();
            }
            catch (Exception ex)
            {
                Response.Write("<body><script>alert(\" " + ex.Message + "\");</script></body>");
            }
        }
    J'attends vos réactions...

  2. #2
    Membre confirmé Avatar de nimois3O
    Profil pro
    Inscrit en
    Mai 2007
    Messages
    183
    Détails du profil
    Informations personnelles :
    Âge : 38
    Localisation : France, Gard (Languedoc Roussillon)

    Informations forums :
    Inscription : Mai 2007
    Messages : 183
    Par défaut
    Bonjour,

    Pour ton "mini probléme" il faut s'implement que tu reprenne ce code :

    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    SqlCommand MyCommand = new SqlCommand();
                MyCommand.Connection = con;
    que tu le copie en dessou par exemple et que tu change les variable (ex MyCommand2)

    voili voilou...

  3. #3
    Membre confirmé Avatar de DaisyVIP
    Profil pro
    Inscrit en
    Mai 2007
    Messages
    160
    Détails du profil
    Informations personnelles :
    Âge : 38
    Localisation : France, Gard (Languedoc Roussillon)

    Informations forums :
    Inscription : Mai 2007
    Messages : 160
    Par défaut
    Ahh ok!!!
    Je vois où est mon erreur!!! Merci beaucoup nimois30!
    donc si je ne me trompe pas, il faut que je mette ça: ?
    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
    {
                con.Open();
                SqlCommand MyCommand1 = new SqlCommand();
                MyCommand1.Connection = con;
                SqlCommand MyCommand2 = new SqlCommand();
                MyCommand2.Connection = con;
     
                MyCommand1.CommandText = "INSERT INTO Etudier(code_course_content, course_content, code_group, code_course) values ('BO:25/08/92','" + txtContent1.Text + "','IG1','3')";
                MyCommand2.CommandText = "INSERT INTO Observation(date, obs_day, code_group) values ('29/05/07','" + txtObs.Text + "','IG1')";
                //SqlDataReader MyDataReader;
                //MyDataReader = 
                MyCommand1.ExecuteReader();
                MyCommand2.ExecuteReader();
     
     
                /*while (MyDataReader.Read())
                {
                    ListBox1.Text = MyDataReader.GetString(1);
                } */
                con.Close();
            }
    Merci de m'avoir répondu!!!

  4. #4
    Membre confirmé Avatar de nimois3O
    Profil pro
    Inscrit en
    Mai 2007
    Messages
    183
    Détails du profil
    Informations personnelles :
    Âge : 38
    Localisation : France, Gard (Languedoc Roussillon)

    Informations forums :
    Inscription : Mai 2007
    Messages : 183
    Par défaut
    Normalement ça devrais marché...

    Pence au

  5. #5
    Membre confirmé Avatar de DaisyVIP
    Profil pro
    Inscrit en
    Mai 2007
    Messages
    160
    Détails du profil
    Informations personnelles :
    Âge : 38
    Localisation : France, Gard (Languedoc Roussillon)

    Informations forums :
    Inscription : Mai 2007
    Messages : 160
    Par défaut
    Il m'affiche un message d'erreur, et du coup il m'affiche que le premier mais pas le deuxième!!! Ben pourquoi???
    A l'aide!!!

  6. #6
    Membre confirmé Avatar de DaisyVIP
    Profil pro
    Inscrit en
    Mai 2007
    Messages
    160
    Détails du profil
    Informations personnelles :
    Âge : 38
    Localisation : France, Gard (Languedoc Roussillon)

    Informations forums :
    Inscription : Mai 2007
    Messages : 160
    Par défaut
    Plus rien ne marche!!!
    Aidez moi, j'ai mis ça:
    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
    SqlConnection con1 = new SqlConnection(MyConstring);
            SqlConnection con2 = new SqlConnection(MyConstring);
     
            try
            {
                con1.Open();
                SqlCommand MyCommand1 = new SqlCommand();
                MyCommand1.Connection = con1;
     
     
                MyCommand1.CommandText = "INSERT INTO Etudier(code_course_content, course_content, code_group, code_course) values ('BO:25/08/92','" + txtContent1.Text + "','IG1','3')";
     
                //SqlDataReader MyDataReader;
                //MyDataReader = 
                MyCommand1.ExecuteReader();
     
     
     
                /*while (MyDataReader.Read())
                {
                    ListBox1.Text = MyDataReader.GetString(1);
                } */
                con1.Close();
     
                con2.Open();
                SqlCommand MyCommand2 = new SqlCommand();
                MyCommand2.Connection = con2;
                MyCommand2.CommandText = "INSERT INTO Observation(date, obs_day, code_group) values ('28/05/07','" + txtObs.Text + "','IG1')";
                MyCommand2.ExecuteReader();
                con2.Close();
            }
     
     
            catch (Exception ex)
            {
                Response.Write("<body><script>alert(\" " + ex.Message + "\");</script></body>");
            }
        }
    Et ni l'un ni l'autre ne fonctionne maintenant!!!

  7. #7
    Membre confirmé Avatar de DaisyVIP
    Profil pro
    Inscrit en
    Mai 2007
    Messages
    160
    Détails du profil
    Informations personnelles :
    Âge : 38
    Localisation : France, Gard (Languedoc Roussillon)

    Informations forums :
    Inscription : Mai 2007
    Messages : 160
    Par défaut
    J'ai mis ça, et plus rien ne marche, pourquoi, je vous en supplie aidez moi!!!
    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
     protected void Button1_Click(object sender, EventArgs e)
        {
            string MyConstring = "Data Source=PROD005\\SQLEXPRESS;uid=PROD005\\mauto-daisy;pwd=uniqu;Initial Catalog='C:\\DOCUMENTS AND SETTINGS\\MAUTO-DAISY\\MES DOCUMENTS\\STAGE_PROJET.MDF';Integrated Security=True";
     
     
            SqlConnection con1 = new SqlConnection(MyConstring);
            SqlConnection con2 = new SqlConnection(MyConstring);
     
            try
            {
                con1.Open();
                SqlCommand MyCommand1 = new SqlCommand();
                SqlCommand MyCommand2 = new SqlCommand();
     
                MyCommand1.Connection = con1;
                MyCommand2.Connection = con2;
     
                MyCommand1.CommandText = "INSERT INTO Etudier(code_course_content, course_content, code_group, code_course) values ('BO:25/08/92','" + txtContent1.Text + "','IG1','3')";
                MyCommand2.CommandText = "INSERT INTO Observation(date, obs_day, code_group) values ('28/05/07','" + txtObs.Text + "','IG1')";
                //SqlDataReader MyDataReader;
                //MyDataReader = 
                MyCommand1.ExecuteReader();
                MyCommand2.ExecuteReader();
     
     
                /*while (MyDataReader.Read())
                {
                    ListBox1.Text = MyDataReader.GetString(1);
                } */
                con1.Close();
            }
     
     
            catch (Exception ex)
            {
                Response.Write("<body><script>alert(\" " + ex.Message + "\");</script></body>");
            }
        }

  8. #8
    Membre confirmé Avatar de nimois3O
    Profil pro
    Inscrit en
    Mai 2007
    Messages
    183
    Détails du profil
    Informations personnelles :
    Âge : 38
    Localisation : France, Gard (Languedoc Roussillon)

    Informations forums :
    Inscription : Mai 2007
    Messages : 183
    Par défaut
    J'ai essayé de faire le code mais je n'y suis pas arrivé...

    Je serais interressai de le connaitre quand méme...

    Merci de répondre...

  9. #9
    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
    Par défaut
    La connexion con2 n'est pas ouverte.
    Dans ce genre de situation, si tu ne postes pas le message d'erreur, c'est difficile de t'aider.
    Quelle est l'erreur affichée ? "plus rien ne marche" ne nous dit pas grandchose.
    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

  10. #10
    Membre confirmé Avatar de DaisyVIP
    Profil pro
    Inscrit en
    Mai 2007
    Messages
    160
    Détails du profil
    Informations personnelles :
    Âge : 38
    Localisation : France, Gard (Languedoc Roussillon)

    Informations forums :
    Inscription : Mai 2007
    Messages : 160
    Par défaut Update
    à priori je crois qu'il faut que j'utilise un Update, mais comment le formuler?

    Le message d'erreur était insensé, et le problème est qu'il ne m'affiche rien du tout dans ma base de donnée.

    Quelqu'un sait-il traiter les updates, pour ce genre de situation???

Discussions similaires

  1. Réponses: 5
    Dernier message: 19/08/2010, 02h10
  2. Problème d'écriture dans ma base de donnée
    Par Gwennin dans le forum SQL Procédural
    Réponses: 3
    Dernier message: 04/03/2008, 13h01
  3. Problème d'écriture dans la base de données
    Par DaisyVIP dans le forum ASP.NET
    Réponses: 13
    Dernier message: 01/02/2008, 10h27
  4. [Hibernate] problème d'insertion dans la base de données
    Par Willy7901 dans le forum Eclipse Java
    Réponses: 1
    Dernier message: 18/08/2005, 13h19
  5. problème de recherche dans une base de données
    Par bouzid_mehdi dans le forum Bases de données
    Réponses: 2
    Dernier message: 19/07/2005, 06h47

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