Bonsoir,

Je ne peut pas insérer des lignes dans ma table, l'erreur est la suivante:

column count doesn't match value row1.

j'ai vérifié les champs, j'ai tous initialisé, mais c'est toujours : column count doesn't match value row1.

Svp aidez moi à trouver l'erreur:

voici mon 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
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
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
    string strConn = "Server = localhost; database = databasepsy; uid= root; pwd = root";
	MySqlConnection cnx = new MySqlConnection();
        MySqlDataAdapter MyAdapter = new MySqlDataAdapter();
 
        string premConsult = "";
        string sexe = "";
        string respLegal = "";
 
	//....
 
	private void btnSavePatient_Click(object sender, EventArgs e)
        {
            string nom = txtBnom.Text;
            string prenom = txtbprenom.Text;
            string dateNaissance = dateTimePickerNaissance.Text;
            string age = txtBage.Text;
            string datPremConsul = dateTimePickerPremCons.Text;
            string datDernConsul = dateTimePickerDernCons.Text;
            string nbreConsul = txtBnbreCons.Text;
            string etatCivil = comboEtatCivil.Text;
            string nomConjoint = txtBnomConj.Text;
            string adress = txtBAdress.Text;
            string cdPostal = txtBcodPost.Text;
            string ville = txtBVille.Text;
            string pays = txtBPays.Text;
            string telMaison = txtBtelMaison.Text;
            string telTravail = txtBTelTrav.Text;
            string autreTel = txtBAutrTel.Text;
            string gsm = txtBGsm.Text;
            string adressePar = txtBAdressePar.Text;
            string Note = txtBNote.Text;
            string ModVie = txtBModVie.Text;
            string nivSocial = comboNiveauSocial.Text;
            string tuteur = txtBTuteur.Text;
 
	    string MySQLCmdEnregistrer = "INSERT INTO patient(id_patient,nom,prenom,date_naissance,age,date_prem_cons,date_dern_cons,nbre_cons,etat_civil,nom_conjoint,adresse,code_postal,ville,pays,tel_maison,tel_travail,autres_tel,gsm,adresse_par,note,sexe,mode_vie,niveau_soscial,responsable_legal,tuteur) VALUES( '' ,'" + nom + "','" + prenom + "','" + dateNaissance + "','" + age + "','" + premConsult + "','" + datPremConsul + "','" + datDernConsul + "','" + nbreConsul + "','" + etatCivil + "','" + nomConjoint + "','" + adress + "','" + cdPostal + "','" + ville + "','" + pays + "','" + telMaison + "','" + telTravail + "','" + autreTel + "','" + gsm + "','" + adressePar + "','" + Note + "','" + sexe + "','" + ModVie + "','" + nivSocial + "','" + respLegal + "','" + tuteur + "')";
 
            MySqlCommand cmd = new MySqlCommand(MySQLCmdEnregistrer, cnx);
 
	    if (nom == "" || prenom == "" || dateNaissance == "" || datPremConsul == "" || etatCivil == "" || ModVie == "")
            {
                MessageBox.Show("Vous devez remplir tous les champs marqué par * ");
            }
            else
            {
 
                try
                {
                    cnx.ConnectionString = strConn;
                    cnx.Open();
                    MessageBox.Show("Connection réussie");
 
                    int nombre = cmd.ExecuteNonQuery();
                    if (nombre != 0)
                    {
                        MessageBox.Show("Un patient a été bien enregistré");
                        txtBnom.Text = "";
                        txtbprenom.Text = "";
                        chckBPremCons.Checked = false;
                        comboEtatCivil.Text = "";
                        txtBnomConj.Text = "";
                        txtBAdress.Text = "";
                        txtBcodPost.Text = "";
                        txtBVille.Text = "";
                        txtBPays.Text = "";
                        txtBtelMaison.Text = "";
                        txtBTelTrav.Text = "";
                        txtBAutrTel.Text = "";
                        txtBGsm.Text = "";
                        txtBAdressePar.Text = "";
                        txtBNote.Text = "";
                        txtBModVie.Text = "";
                        txtBTuteur.Text = "";
                        txtBnom.Focus();
                    }
 
                    cnx.Close();
 
                }
 
                catch (Exception ex)
                {
                    MessageBox.Show("Problème de connection " + ex.Message);
                }
            }
 
//.....
 
            private void txtBage_TextChanged(object sender, EventArgs e)
        {
            int agecalcule = int.Parse(txtBage.Text);
            if (agecalcule > 20 || (chckBWiRespLegal.Checked) == false)
            {
                labelRespLegal.ForeColor = System.Drawing.Color.Gray;
                labelTuteur.ForeColor = System.Drawing.Color.Gray;
                chckBWiRespLegal.Enabled = false;
                chckBNonRespLegal.Enabled = false;
                txtBTuteur.Enabled = false;
 
            }
            else if (agecalcule < 20 && (chckBWiRespLegal.Checked) == true)
            {
                labelRespLegal.ForeColor = System.Drawing.Color.Black;
                labelTuteur.ForeColor = System.Drawing.Color.Black;
                txtBTuteur.Enabled = true;
                respLegal = txtBTuteur.Text;
            }
        }
 
        private void chckBWiRespLegal_CheckedChanged(object sender, EventArgs e)
        {
            if (chckBWiRespLegal.Checked== true)
            chckBNonRespLegal.Checked = false;
            else
                chckBNonRespLegal.Checked = true;
        }
 
        private void chckBNonRespLegal_CheckedChanged(object sender, EventArgs e)
        {
            if (chckBNonRespLegal.Checked == true)
                chckBWiRespLegal.Checked = false;
            else
                chckBWiRespLegal.Checked = true;
 
        }
        public int GetAge(DateTime DateDeNaissance)
        {
		int age = DateTime.Now.Year - DateDeNaissance.Year;
		DateTime DateAnniv = new DateTime(DateTime.Now.Year, DateDeNaissance.Month, DateDeNaissance.Day);
		if (DateAnniv > DateTime.Now)
		age--;
 
            return age;
        }
 
	 private void dateTimePickerNaissance_ValueChanged(object sender, EventArgs e)
        {
            DateTime DateNaiss = dateTimePickerNaissance.Value;
 
            txtBage.Text= (GetAge(DateNaiss)).ToString();
 
        }
  }
}
Merci infiniment.