private void add(string design, string matricule, string qte, string type, string service, string fournisseur)
{
string sql = "INSERT INTO db(designation-mat,matricule-mat,qte-mat,type-mat,service,fournisseur) VALUES (@DESIGN,@MATRICULE,@QTE,@TYPE,@SERVICE,@FOURNISSEUR)";
cmd = new MySqlCommand(sql, con);
cmd.Parameters.AddWithValue("@DESIGN", design);
cmd.Parameters.AddWithValue("@MATRICULE", Convert.ToInt32(matricule));
cmd.Parameters.AddWithValue("@QTE", Convert.ToInt32(qte));
cmd.Parameters.AddWithValue("@TYPE", type);
cmd.Parameters.AddWithValue("@SERVICE", service);
cmd.Parameters.AddWithValue("@FOURNISSEUR", fournisseur);
try
{
con.Open();
if (cmd.ExecuteNonQuery() > 0)
{
cleartxts();
MessageBox.Show("SuccessFuly Inserted!");
}
con.Close();
retrieve();
}
}
Asked
Active
Viewed 45 times
0
-
2Perhaps column with hypens like `designation-mat` need to be quoted: `"designation-mat"`, or backticks (`\``) or however it's done in MySQL. https://stackoverflow.com/questions/2889871/how-do-i-escape-reserved-words-used-as-column-names-mysql-create-table – 15ee8f99-57ff-4f92-890c-b56153 Sep 08 '17 at 15:05
-
can you provide a proper description so that we can able to help you – Santhakumar Munuswamy Sep 08 '17 at 15:06
-
Please add a body to your question not just code. A title should bring people to your question and not be entire question in of itself. – Error - Syntactical Remorse Sep 08 '17 at 15:06
-
ok i will edit the title – Rad304 Sep 08 '17 at 15:12
1 Answers
2
Try to use ` around the column names:
string sql = "INSERT INTO db (`designation-mat`, `matricule-mat`, `qte-mat`, `type-mat`, service, fournisseur) VALUES (@DESIGN, @MATRICULE, @QTE, @TYPE, @SERVICE, @FOURNISSEUR)";
It is brackets [...] if you use SQL Server.

mm8
- 163,881
- 10
- 57
- 88