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 :

Comportement bizarre de ma requête.


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 Comportement bizarre de ma requête.
    Bonjour,
    J’ai fait un code pour charger des données sur un comobox ensuite j’ai fait une requête select,
    Le problème c’est que la requête s’effectue bizarrement la première fois, par contre quand je ressaye il fonctionne bien…

    PS ; j’ai travaillé avec le mode debug et le point d’arrêt il ya pas d’erreur
    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
    55
    56
    57
    58
    59
    60
    61
    62
    63
    64
    65
     
    private void chercher_projet_Load(object sender, EventArgs e)
            {
                DataSet ds = new DataSet();
                // Chaîne de connexion 
                string connectString = @"Data Source=RENNDXPRDL2596\SQLEXPRESS;Initial Catalog=hafid;Integrated Security=True";
                // Objet connection 
                SqlConnection connection = new SqlConnection(connectString);
     
                SqlDataAdapter Da_Table_Project = new SqlDataAdapter("SELECT ID_project FROM [Table_Project]", connection);
     
                Da_Table_Project.Fill(ds, "Table_Project");
     
                comboBox_cherche.DataSource = ds.Tables["Table_Project"];
                comboBox_cherche.DisplayMember = "ID_project";
                comboBox_cherche.ValueMember = "ID_project";
            }
     
     
     
            private void button1_Click(object sender, EventArgs e)
            {
     
                if (String.IsNullOrEmpty(comboBox_cherche.Text))
                {
     
                    MessageBox.Show("You must fill the name of project", " Reconfigure", MessageBoxButtons.OK, MessageBoxIcon.Error);
                }
                else
                {
                    ma_form_modifyproject.project_name = comboBox_cherche.Text;
                    ma_form_modifyproject.ShowDialog();
     
                } try
                {
                    // 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("SELECT * FROM [Table_Project] WHERE ([ID_project]='" + comboBox_cherche.Text + "');", connection);
     
                    SqlDataReader reader = command.ExecuteReader();
                    while (reader.Read())
                    {
                        ma_form_modifyproject.project_name = reader["ID_project"].ToString();
                        ma_form_modifyproject.project_category = reader["Project Category"].ToString();
                        ma_form_modifyproject.datte = reader["kick off date"].ToString();
                        ma_form_modifyproject.location = reader["Location"].ToString();
                    }
                    // Fermeture reader
                    reader.Close();
                    // Fermeture connection
                    connection.Close();
                }
                catch (Exception ex)
                {
                    MessageBox.Show(ex.ToString());
                }
            } 
        }
     
    }
    merci

  2. #2
    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
    Je pige rien, c'est quoi qui marche pas exactement ? Parce que là y'a 2 requêtes.

  3. #3
    Rédacteur/Modérateur


    Homme Profil pro
    Développeur .NET
    Inscrit en
    Février 2004
    Messages
    19 875
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Âge : 43
    Localisation : France, Paris (Île de France)

    Informations professionnelles :
    Activité : Développeur .NET
    Secteur : High Tech - Éditeur de logiciels

    Informations forums :
    Inscription : Février 2004
    Messages : 19 875
    Points : 39 753
    Points
    39 753
    Par défaut
    et ça veut dire quoi, "la requête s'effectue bizarrement" ? on est pas devins...

  4. #4
    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
    bonsoir,
    en fait quand je lance mon programme, la chargement du comobox s'effectue correctement,
    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
     
    private void chercher_projet_Load(object sender, EventArgs e)
            {
                DataSet ds = new DataSet();
                // Chaîne de connexion 
                string connectString = @"Data Source=RENNDXPRDL2596\SQLEXPRESS;Initial Catalog=hafid;Integrated Security=True";
                // Objet connection 
                SqlConnection connection = new SqlConnection(connectString);
     
                SqlDataAdapter Da_Table_Project = new SqlDataAdapter("SELECT ID_project FROM [Table_Project]", connection);
     
                Da_Table_Project.Fill(ds, "Table_Project");
     
                comboBox_cherche.DataSource = ds.Tables["Table_Project"];
                comboBox_cherche.DisplayMember = "ID_project";
                comboBox_cherche.ValueMember = "ID_project";
            }
    par contre ma deuxieme requête
    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
     
            private void button1_Click(object sender, EventArgs e)
            {
     
                if (String.IsNullOrEmpty(comboBox_cherche.Text))
                {
     
                    MessageBox.Show("You must fill the name of project", " Reconfigure", MessageBoxButtons.OK, MessageBoxIcon.Error);
                }
                else
                {
                    ma_form_modifyproject.project_name = comboBox_cherche.Text;
                    ma_form_modifyproject.ShowDialog();
     
                } try
                {
                    // 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("SELECT * FROM [Table_Project] WHERE ([ID_project]='" + comboBox_cherche.Text + "');", connection);
     
                    SqlDataReader reader = command.ExecuteReader();
                    while (reader.Read())
                    {
                        ma_form_modifyproject.project_name = reader["ID_project"].ToString();
                        ma_form_modifyproject.project_category = reader["Project Category"].ToString();
                        ma_form_modifyproject.datte = reader["kick off date"].ToString();
                        ma_form_modifyproject.location = reader["Location"].ToString();
                    }
                    // Fermeture reader
                    reader.Close();
                    // Fermeture connection
                    connection.Close();
                }
                catch (Exception ex)
                {
                    MessageBox.Show(ex.ToString());
                }
            } 
        }
     
    }
    ne marche pas la premiére fois quand je click sur le bouton ,et quand je réessaie ca me donne le bon resultat

  5. #5
    Rédacteur/Modérateur


    Homme Profil pro
    Développeur .NET
    Inscrit en
    Février 2004
    Messages
    19 875
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Âge : 43
    Localisation : France, Paris (Île de France)

    Informations professionnelles :
    Activité : Développeur .NET
    Secteur : High Tech - Éditeur de logiciels

    Informations forums :
    Inscription : Février 2004
    Messages : 19 875
    Points : 39 753
    Points
    39 753
    Par défaut
    Ca veut dire quoi, "ne marche pas" ? il y a une erreur (laquelle ?) ? la requête ne renvoie rien ? elle renvoie n'importe quoi ?
    Sois plus précis dans la description de ton problème, ce sera plus facile pour t'aider...

    Je vois déjà un truc qui ne va pas, c'est que le bloc qui exécute la requête devrait être dans le else précédent, sinon rien ne garantit que comboBox_cherche.Text soit renseigné.

  6. #6
    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
    oui ma deusiéme requête m'envoie n'importe quoi, mais le plus bizzard c'est que quand je j'insiste la deuxième fois ca me donne le bon resultat

  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
    c'est bon c'été un probleme de eles ,
    merci tomlev

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

Discussions similaires

  1. Requête mysql lancée par ajax comportement bizarre
    Par reventlov dans le forum AJAX
    Réponses: 4
    Dernier message: 06/07/2015, 21h38
  2. [AJAX] Comportement bizarre d’IE avec les requêtes AJAX
    Par yassinbean dans le forum jQuery
    Réponses: 2
    Dernier message: 26/04/2013, 17h52
  3. Réponses: 3
    Dernier message: 10/04/2008, 15h06
  4. [HttpClient] comportement bizarre, saute des catch()...
    Par iubito dans le forum Développement Web en Java
    Réponses: 4
    Dernier message: 04/02/2004, 15h25
  5. [Sybase] Comportement bizarre d'une table
    Par sdozias dans le forum Sybase
    Réponses: 4
    Dernier message: 03/02/2004, 10h39

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