mardi 24 novembre 2015

SQLite error "Insufficient parameters supplied to the command"

I'm having a problem with SQLite/Dapper where I am getting an "Insufficient parameters supplied to the command" error. I realise this question get asked a lot, but all of the answers I have found on the internet point towards missing parameters or spelling mistakes, but I don't see any here.

I have an existing database table I am trying to add information to:

 CREATE TABLE 'Question' (
                        'Id' INTEGER PRIMARY KEY  AUTOINCREMENT  NOT NULL ,
                        'Text' TEXT NOT NULL ,
                        'CategoryId' INTEGER NOT NULL ,
                        'IsMultipleChoice' BOOL NOT NULL  DEFAULT TRUE,
                        FOREIGN KEY (CategoryId) REFERENCES Category(Id));

I have a class representing the object that is to be added to the database:

class Question
        {
           public int Id { get; set; }
           public string Text { get; set; }
           public int CategoryId;
           public bool IsMultipleChoice { get; set; }
        }

And a method to add a class to the SQLite database using Dapper

public Question Add(Question question)
        {
            using (var conn = BaseDatabase.dbConnection())
            {
                    var sqlQuery = @"INSERT INTO Question (Text, CategoryId, IsMultipleChoice) 
                                     VALUES(@Text, @CategoryId, @IsMultipleChoice); 
                                     SELECT CAST(last_insert_rowid() as int)";
                    var questionId = conn.Query<int>(sqlQuery, question).Single();
                    question.Id = questionId;
                    return question;
            }
        }

I have a method for a table that has an Id and Name field which is exactly the same but only passes a Name parameter and that works fine.

Aucun commentaire:

Enregistrer un commentaire