I am getting and error Incorrect syntax near keyword 'Order'.
protected void btnSubmit_Click(object sender, EventArgs e)
{
SqlCommand cmd = new SqlCommand("Insert INTO Order (Cust_Num, Sale_Num) VALUES (@cust_num, @sale_num))", conn);
cmd.CommandType = CommandType.Text;
cmd.Parameters.AddWithValue("@cust_num", txtBxCustNum.Text);
cmd.Parameters.AddWithValue("@sale_num", txtBxSaleNum.Text);
conn.Open();
cmd.ExecuteNonQuery();
conn.Close();
}
Order
is a key word used in Order by
Correct like this
SqlCommand cmd = new SqlCommand("Insert INTO [Order] (Cust_Num, Sale_Num) VALUES (@cust_num, @sale_num))", conn);
Use [] to escape keywords that appear in table or column names.
Order
is a reserved word, and as such IMHO a bad name for a table. Nonetheless, you need to escape the name by wrapping it in square brackets:
SqlCommand cmd = new SqlCommand("Insert INTO [Order] (Cust_Num, Sale_Num) VALUES (@cust_num, @sale_num))", conn);
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.