I get an error when I try to run this method:
public bool InsertLog(string logMsg, string type)
{
bool result = false;
string sql = "INSERT INTO `log`(`logmsg`, `type`) VALUES (?a, ?b)";
using (SQLiteConnection conn = new SQLiteConnection(m_dbConnectionString))
{
conn.Open();
using (var comm = conn.CreateCommand())
{
comm.CommandText = sql;
comm.Parameters.AddWithValue("?a", logMsg);
comm.Parameters.AddWithValue("?b", type);
int res = comm.ExecuteNonQuery();
result = (res == 1);
}
conn.Close();
}
return result;
}
On this database table:
CREATE TABLE log (
id INTEGER PRIMARY KEY,
createdAt DATETIME DEFAULT (datetime('now', 'localtime') ),
logmsg TEXT,
type VARCHAR
);
The error message is {"SQL logic error or missing database\r\nnear \"a\": syntax error"} (System.Data.SQLite.SQLiteExpcetion). Where is the syntax error in the insert query? I don't see it. Can't I use prepared statements this way?