Every time I try to run, error pop ups saying
Syntax Error Insert Into
I've tried changing the statement by putting [] braces as there are no reserved keyword.
connection.Open();
OleDbCommand command = new OleDbCommand();
command.Connection = connection;
command.CommandText = "INSERT INTO lectrical([ItemName],Type,Quantity,Retail,Sale) value('"+ txtItemName.Text +` `"','" + txtType.Text + "','" + Convert.ToDecimal(txtQuantity.Text) + "','" +` `Convert.ToDecimal(txtRetail.Text) + "','" + Convert.ToDecimal(txtSale.Text) +` `"') ";
command.ExecuteNonQuery();
The error is in this part of query:
"INSERT INTO lectrical([ItemName],Type,Quantity,Retail,Sale) value(..."
You wrote value
- should be values
. Also, Type
should be in []
, it is reserved keyword.
Your query should be:
command.CommandText = "INSERT INTO lectrical(ItemName,[Type],Quantity,Retail,Sale) values('"+ txtItemName.Text +` `"','" + txtType.Text + "','" + Convert.ToDecimal(txtQuantity.Text) + "','" +` `Convert.ToDecimal(txtRetail.Text) + "','" + Convert.ToDecimal(txtSale.Text) +` `"') ";
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.