1

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.

1
  • 1
    Values is a reserved word in SQL. You have to escape the name in your INSERT statement the same way you did in your CREATE statement. Commented Nov 28, 2017 at 18:51

1 Answer 1

3

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.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.