I have a C# Winform app witch uses the following SQL insert code but for some reason i get an error, the statement is:
private void button1_Click(object sender, EventArgs e)
{
if (desemp.Text != "" && valu.Text != "" && fs.Text != "" && sel.Text != "" && desc.Text != "" && ench.Text != "" && comp.Text != "")
{
cmd = new SqlCommand("insert into dbo.vidros(desempenho,valu,fs,sel,desc,enchimento,compo) values (@desemp,@valu,@fs,@sel,@desc,@ench,@comp)", con);
con.Open();
cmd.Parameters.AddWithValue("@desemp", desemp.Text);
cmd.Parameters.AddWithValue("@valu", valu.Text);
cmd.Parameters.AddWithValue("@fs", fs.Text);
cmd.Parameters.AddWithValue("@sel", sel.Text);
cmd.Parameters.AddWithValue("@desc", desc.Text);
cmd.Parameters.AddWithValue("@ench", ench.Text);
cmd.Parameters.AddWithValue("@comp", comp.Text);
cmd.ExecuteNonQuery();
con.Close();
MessageBox.Show("sucess!");
}
else
{
MessageBox.Show("Error!");
}
}
The error i get is: Incorrect Syntax near the word 'desc'. I lost hours trying to figure this one out and cant find the fault.
Can anyone help?
Thanks in advance
descis a reserved word, for ordering.descis a keyword?descis indeed a keyword. Use[desc](with square brackets) if you really want to stick to it, although, I would not recommend it.cmd.CommandTypebeforecmd.ExecuteNonQuery();