Reputation: 679
I'm receiving this error '{"SQLite error\r\nnear \"Values\": syntax error"}'. with the following block of code.
using (SQLiteConnection connection = new SQLiteConnection())
{
connection.ConnectionString = ConnectionString;
connection.Open();
using (SQLiteCommand insertSQL = new SQLiteCommand(connection))
{
insertSQL.CommandText = "INSERT INTO BetaValues(Name, Values) VALUES(@param1, @param2)";
//insertSQL.CommandType = CommandType.Text;
insertSQL.Parameters.Add("@param1", DbType.String).Value = beta.Name.ToString();
insertSQL.Parameters.Add("@param2", DbType.String).Value = beta.ValuesXML.ToString();
insertSQL.ExecuteNonQuery();
}
The data definition of my table is the following.
CREATE TABLE BetaValues (
idBetaValues INTEGER PRIMARY KEY,
Name STRING (20) NOT NULL
UNIQUE,
[Values] TEXT UNIQUE
);
I've been trying to wrap my head around this error, but I can't find the reason why I'm receiving the previous error.
Upvotes: 1
Views: 413
Reputation: 11389
Since VALUES
is a SQL operator you need to use a delimited identifier to identify the column correctly. In SQLite you could to add square brackets [ColumnName]
around the column name. Note that there are also other quotes possible. Have a look at the create query you've already written and modify your insert statement like
INSERT INTO BetaValues(Name, [Values]) VALUES(@param1, @param2)
to solve your problem.
Upvotes: 3