Skip to content

Exception in Mysql.data.dll

Bendaoud achraf

Asked Jun 21, 2016, 5:49 AM EDT1 answer
Share
LinkedInX
hello,
i'm working on a forms application where i need to insert data into mysql db and here's the code:
 
 
public const string query = "INSERT INTO facturation (Projet,N-facture,Total-HT,Retenue-garantie-10%,Retenue-avance,Montant-HT,TVA,TTC,Payement1,Date1,Payement2,Date2,Payement3,Date3,Payement4,Date4) VALUES (@Projet,@N-facture,@Total-HT,@Retenue-garantie-10%,@Retenue-avance,@Montant-HT,@TVA,@TTC,@Payement1,@Date1,@Payement2,@Date2,@Payement3,@Date3,@Payement4,@Date4)";
 
Java
 using (MySqlConnection conn = new MySqlConnection(Datacon.con))
            {
                int Nfacture = 1;
                float TotalHT = 1;
                float Retenuegarantie10 = 1;
                float Retav = 1;
                float MontHT = 1;
                float TVA = 1;
                float TTC = 1;
                float P1 = 1;
                float P2 = 1;
                float P3 = 1;
                float P4 = 1;


                DateTime D1 = DateTime.Now.Date;
                DateTime D2 = DateTime.Now.Date;
                DateTime D3 = DateTime.Now.Date;
                DateTime D4 = DateTime.Now.Date;


                MySqlCommand com = new MySqlCommand(Datacon.query, conn);
                f2 f21 = new f2();


                com.Parameters.AddWithValue("@Projet", f21.textBox1.Text);
                com.Parameters.AddWithValue("@N-facture", int.TryParse(f21.textBox2.Text,out Nfacture));
                com.Parameters.AddWithValue("@Total-HT", float.TryParse(f21.textBox3.Text,out TotalHT));
                com.Parameters.AddWithValue("@Retenue-garantie-10%", float.TryParse(f21.textBox4.Text,out Retenuegarantie10));
                com.Parameters.AddWithValue("@Retenue-avance", float.TryParse(f21.textBox5.Text,out Retav));
                com.Parameters.AddWithValue("@Montant-HT", float.TryParse(f21.textBox6.Text,out MontHT));
                com.Parameters.AddWithValue("@TVA", float.TryParse(f21.textBox7.Text,out TVA));
                com.Parameters.AddWithValue("@TTC", float.TryParse(f21.textBox8.Text,out TTC));
                com.Parameters.AddWithValue("@Payement1", float.TryParse(f21.textBox9.Text,out P1));
                com.Parameters.AddWithValue("@Date1", DateTime.TryParse(f21.textBox10.Text,out D1));
                com.Parameters.AddWithValue("@Payement2", float.TryParse(f21.textBox11.Text,out P2));
                com.Parameters.AddWithValue("@Date2", DateTime.TryParse(f21.textBox12.Text,out D2));
                com.Parameters.AddWithValue("@Payement3", float.TryParse(f21.textBox13.Text,out P3));
                com.Parameters.AddWithValue("@Date3", DateTime.TryParse(f21.textBox14.Text,out D3));
                com.Parameters.AddWithValue("@Payement4", float.TryParse(f21.textBox15.Text,out P4));
                com.Parameters.AddWithValue("@Date4", DateTime.TryParse(f21.textBox16.Text, out D4));


                conn.Open();

                try {
                    com.ExecuteNonQuery();
                    MessageBox.Show("sauvegarde remplie!");
                }catch(MySqlException )
                      {
                    MessageBox.Show("Erreur!");
                }
                conn.Close();

            }
        }
 
 
the exception is thrown in  com.ExecuteNonQuery(); as you would have guessed 
please advise 

1 Answer

Know the answer? Post it. Somebody with the same question will find it here.

  • 0
    problem solved
    to whom it may matter it was the query text acting up,
    however i've discovered that using tryparse is not what's needed because it returns the value of a failed parse which is 0
    0