Exception Details: System.Data.OleDb.OleDbException: Syntax error in INSERT INTO statement.
Source Error:
Line 168: comm.Parameters.Add(param);
Line 169:
Line 170: int totalCount = comm.ExecuteNonQuery();
Line 171: conn.Close();
Line 172:
I keep getting the error message "Syntax error in INSERT INTO statement" when the code run to the following method:
protected void makeOrder()
{
OleDbConnection conn = new OleDbConnection();
conn.ConnectionString = ConfigurationManager.ConnectionStrings["onlineStoreConnString"].ConnectionString;
conn.Open();
OleDbCommand comm = conn.CreateCommand();
comm.CommandText = "INSERT INTO Order (UserID, ProductID, OrderDate, ProductQty, IsCart) VALUES(?, ?, ?, ?, ?)";
OleDbParameter param;
param = comm.CreateParameter();
param.DbType = DbType.String;
param.Direction = ParameterDirection.Input;
param.Value = Int32.Parse(Session["LoggedInId"].ToString());
comm.Parameters.Add(param);
param = comm.CreateParameter();
param.DbType = DbType.String;
param.Direction = ParameterDirection.Input;
param.Value = Int32.Parse(Request.QueryString["id"].ToString());
comm.Parameters.Add(param);
param = comm.CreateParameter();
param.DbType = DbType.String;
param.Direction = ParameterDirection.Input;
param.Value = DateTime.Now.ToString();
comm.Parameters.Add(param);
param = comm.CreateParameter();
param.DbType = DbType.String;
param.Direction = ParameterDirection.Input;
param.Value = Int32.Parse(txtQty.Text);
comm.Parameters.Add(param);
param = comm.CreateParameter();
param.DbType = DbType.String;
param.Direction = ParameterDirection.Input;
param.Value = true;
comm.Parameters.Add(param);
int totalCount = comm.ExecuteNonQuery();
conn.Close();
}
The database is MS Access, and the data type of the attributes are UserID: Number,
ProductID: Number,
OrderDate: Long Text,
ProductQty: Number
IsCart: Yes/No
I have been sticking in this bug for couple hours, any can help me find it? Thanks.
Orderis a reserved keyword. Surround it with double-quotes or backticks (if using mysql) - Vamsi Prabhala