Erreur exception
gerwech
-
gerwech -
gerwech -
salut tout le monde,
je bosse avec c#, j'utilise le visual studio 2012 , je termie déja toutes les interfaces ,
mais j'ai une petite problème dans le code
j'ai une interface d'ajout qui permet d'ajouter des données dans trois tables, donc une seul interfaces ajoute les données avec la requète "insert" dans 3 tables , un erreur est affiché:
ERROR [HY000] [MySQL][ODBC 5.2(w) Driver][mysqld-5.5.8]Column count doesn't match value count at row 1
et voila mon code de cet interface:
void Button3Click(object sender, System.EventArgs e)
{
string connectionString;
connectionString = "Dsn=127.0.0.1;server=localhost;uid=root;database=traffic;port=3306";
OdbcConnection connection = new OdbcConnection(connectionString);
connection.Open();
if (connection.State == ConnectionState.Open)
{
MessageBox.Show("connexion effectuée");
}
if ((txt1.Text.Length == 0) | (txt2.Text.Length == 0) | (txt3.Text.Length == 0) | (txt4.Text.Length == 0) | (txt5.Text.Length == 0) | (txt6.Text.Length == 0) | (txt7.Text.Length == 0) | (txt8.Text.Length == 0)|(txt9.Text.Length == 0) | (txt10.Text.Length == 0))
{
MessageBox.Show("Veuillez remplir tous les champs",
"Erreur",
MessageBoxButtons.OK,
MessageBoxIcon.Exclamation,
MessageBoxDefaultButton.Button1);
}
string ajout1 = "insert into serviceconversationnel (DureeMoyCommConver,TauxArrCommConver,TauxActConver) values('" + txt1.Text.ToString() + "','" + txt2.Text.ToString() + "' '" + txt3.Text.ToString() + "' )";
string ajout2 = "insert into serviceinteactif (DureeMoyCommInter,TauxArrCommInter,TauxActInter) values('" + txt4.Text.ToString() + "','" + txt5.Text.ToString() + "' '" + txt6.Text.ToString() + "' )";
string ajout3 = "insert into servicestreaming (DureeMoyCommStreaming,TauxArrCommStreaming,TauxActStreaming) values('" + txt7.Text.ToString() + "','" + txt8.Text.ToString() + "' '" + txt9.Text.ToString() + "' )";
string ajout4 = "insert into service (idService,Gos) values ('" + txt10.Text.ToString() +"' )";
//ajout1
OdbcCommand cmd1 = new OdbcCommand();
cmd1.Connection = connection;
cmd1.CommandText = ajout1;
cmd1.ExecuteNonQuery();
// ajout2
OdbcCommand cmd2 = new OdbcCommand();
cmd2.Connection = connection;
cmd2.CommandText = ajout1;
cmd2.ExecuteNonQuery();
// ajout3
OdbcCommand cmd3 = new OdbcCommand();
cmd3.Connection = connection;
cmd3.CommandText = ajout1;
cmd3.ExecuteNonQuery();
//ajout4
OdbcCommand cmd4 = new OdbcCommand();
cmd4.Connection = connection;
cmd4.CommandText = ajout4;
cmd4.ExecuteNonQuery();
MessageBox.Show("ajout données opérateur est effectuée avec succées");
this.Hide();
Divers d=new Divers();
d.Show();
}
prière de m'aider , c'est urgent , 5 jours et je présente mon projet fin d'étude!
et merci d'avance
je bosse avec c#, j'utilise le visual studio 2012 , je termie déja toutes les interfaces ,
mais j'ai une petite problème dans le code
j'ai une interface d'ajout qui permet d'ajouter des données dans trois tables, donc une seul interfaces ajoute les données avec la requète "insert" dans 3 tables , un erreur est affiché:
ERROR [HY000] [MySQL][ODBC 5.2(w) Driver][mysqld-5.5.8]Column count doesn't match value count at row 1
et voila mon code de cet interface:
void Button3Click(object sender, System.EventArgs e)
{
string connectionString;
connectionString = "Dsn=127.0.0.1;server=localhost;uid=root;database=traffic;port=3306";
OdbcConnection connection = new OdbcConnection(connectionString);
connection.Open();
if (connection.State == ConnectionState.Open)
{
MessageBox.Show("connexion effectuée");
}
if ((txt1.Text.Length == 0) | (txt2.Text.Length == 0) | (txt3.Text.Length == 0) | (txt4.Text.Length == 0) | (txt5.Text.Length == 0) | (txt6.Text.Length == 0) | (txt7.Text.Length == 0) | (txt8.Text.Length == 0)|(txt9.Text.Length == 0) | (txt10.Text.Length == 0))
{
MessageBox.Show("Veuillez remplir tous les champs",
"Erreur",
MessageBoxButtons.OK,
MessageBoxIcon.Exclamation,
MessageBoxDefaultButton.Button1);
}
string ajout1 = "insert into serviceconversationnel (DureeMoyCommConver,TauxArrCommConver,TauxActConver) values('" + txt1.Text.ToString() + "','" + txt2.Text.ToString() + "' '" + txt3.Text.ToString() + "' )";
string ajout2 = "insert into serviceinteactif (DureeMoyCommInter,TauxArrCommInter,TauxActInter) values('" + txt4.Text.ToString() + "','" + txt5.Text.ToString() + "' '" + txt6.Text.ToString() + "' )";
string ajout3 = "insert into servicestreaming (DureeMoyCommStreaming,TauxArrCommStreaming,TauxActStreaming) values('" + txt7.Text.ToString() + "','" + txt8.Text.ToString() + "' '" + txt9.Text.ToString() + "' )";
string ajout4 = "insert into service (idService,Gos) values ('" + txt10.Text.ToString() +"' )";
//ajout1
OdbcCommand cmd1 = new OdbcCommand();
cmd1.Connection = connection;
cmd1.CommandText = ajout1;
cmd1.ExecuteNonQuery();
// ajout2
OdbcCommand cmd2 = new OdbcCommand();
cmd2.Connection = connection;
cmd2.CommandText = ajout1;
cmd2.ExecuteNonQuery();
// ajout3
OdbcCommand cmd3 = new OdbcCommand();
cmd3.Connection = connection;
cmd3.CommandText = ajout1;
cmd3.ExecuteNonQuery();
//ajout4
OdbcCommand cmd4 = new OdbcCommand();
cmd4.Connection = connection;
cmd4.CommandText = ajout4;
cmd4.ExecuteNonQuery();
MessageBox.Show("ajout données opérateur est effectuée avec succées");
this.Hide();
Divers d=new Divers();
d.Show();
}
prière de m'aider , c'est urgent , 5 jours et je présente mon projet fin d'étude!
et merci d'avance
3 réponses
-
Bonjour
À vue de nez, il te manque des virgules entre tes 2 ème et 3 ème values de tes différentes requêtes : + "' '" + à remplacer par + "','" +
Pour ta string4, il te manque carrément une valeur sur les deux, je ne peux pas deviner ce qu'il faut mettre. -
Le père merci pout ton aide ...je vais corriger les fautes et vous envoyer le code de nouveau
-