SQLite error Insufficient parameters supplied to the command at Mono.Data.Sqlite.SqliteStatement.BindParameter

18,681

Solution 1

Your spelling for @Category in INSERT statement is different from added parameter. You have:

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

Where it should be:

Modify your statement to:

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

Solution 2

This has already been answered correctly, but I wish to add, for further information:

This specific SQLite error string can also be generated if any of the @Parameters are spelled differently in the INSERT statement vs the AddWithValue or .Add(new SqliteParameter... statements.

Share:
18,681

Related videos on Youtube

Has AlTaiar
Author by

Has AlTaiar

if you are interested and have time to kill, you could visit my technical blog on HasAlTaiar.com.au

Updated on June 17, 2022

Comments

  • Has AlTaiar
    Has AlTaiar 11 months

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

    When inserting to the database, it says

    SQLite error Insufficient parameters supplied to the command at Mono.Data.Sqlite.SqliteStatement.BindParameter

    I think there is either a bug, or the error message is misleading. Because I only have 5 parameters and I am providing 5 parameters, so I cannot see how this 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);
    }
    
  • Has AlTaiar
    Has AlTaiar about 10 years
    Thanks for that, this was embarrassing :)

Related