SQLite Error Insufficient parameters provided to command in Mono.Data.Sqlite.SqliteStatement.BindParameter

I have a simple insert statement for a table in a SQLite database on MonoDroid.

When pasted into the database it says:

SQLite Error Insufficient parameters provided to command in Mono.Data.Sqlite.SqliteStatement.BindParameter

I think there is either an error or the error message is misleading. Because I have only 5 parameters, and I provide 5 parameters, so I don’t see how it will be right.

My code is below and any help would be greatly appreciated.

try
{
    using (var connection = new SqliteConnection(ConnectionString))
    {
        connection.Open();
        using (var command = connection.CreateCommand())
        {
            command.CommandTimeout = 0;
            command.CommandText = "INSERT INTO [User] (UserPK ,Name ,Password ,Category ,ContactFK) VALUES ( @UserPK , @Name , @Password , @Category , @ContactFK)";
            command.Parameters.Add(new SqliteParameter("@Name", "Has"));
            command.Parameters.Add(new SqliteParameter("@Password", "Has"));
            command.Parameters.Add(new SqliteParameter("@Cateogry", ""));
            command.Parameters.Add(new SqliteParameter("@ContactFK", DBNull.Value));
            command.Parameters.Add(new SqliteParameter("@UserPK", DbType.Guid) {Value = Guid.NewGuid()});
            var result = command.ExecuteNonQuery();
            return = result > 0 ;
        }
    }
}
catch (Exception exception)
{
    LogError(exception);
}
+5
source share
2 answers

Your spelling for @Categorythe INSERT statement is different from the parameter added. You have:

command.Parameters.Add(new SqliteParameter("@Cateogry", ""));
                                           ^^^^^^^^^^^
                                           //@Category

Where should it be:

Change your expression to:

command.Parameters.Add(new SqliteParameter("@Category", ""));
+7
source

, , :

SQLite , @Parameters - INSERT AddWithValue .Add( SqliteParameter...

+1

All Articles