"Syntax error in INSERT INTO statement". Why?
Posted
by Kevin
on Stack Overflow
See other posts from Stack Overflow
or by Kevin
Published on 2010-04-07T10:26:03Z
Indexed on
2010/04/07
10:33 UTC
Read the original article
Hit count: 147
My code is below. I have a method where I pass in three parameters and they get written out to an MS Access database table. However, I keep getting a syntax error message. Can anyone tell me why? I got this example from the internet.
private static void insertRecord(string day, int hour, int loadKW)
{
string connString = @"Provider=Microsoft.ACE.OLEDB.12.0;Data Source=C:\LoadForecastDB.accdb";
OleDbConnection conn = new OleDbConnection(connString);
string ins = @"INSERT INTO Forecasts (Day, Hour, Load) VALUES (?,?,?)";
OleDbCommand cmd = new OleDbCommand(ins, conn);
cmd.Parameters.Add("@day", OleDbType.VarChar).Value = day;
cmd.Parameters.Add("@hour", OleDbType.Integer).Value = hour;
cmd.Parameters.Add("@load", OleDbType.Integer).Value = loadKW;
conn.Open();
try
{
int count = cmd.ExecuteNonQuery();
}
catch (OleDbException ex)
{
Console.WriteLine(ex.Message);
}
finally
{
conn.Close();
}
}
© Stack Overflow or respective owner