1

When querying data from SQLite, it says:

SQLite error Insufficient parameters supplied to the command

I think there is either a bug, or the error message is misleading. Because I only have one parameter and I am providing it, so I cannot understand where is the problem.

Here is my code:

public List<T> Read(string sql, List<SQLiteParameter> addParametera = null, params string[] properties)
{
    var data = new DataTable();

    var command = new SQLiteCommand(Connection);
    command.CommandText = sql;
    addParametera?.ForEach(p => command.Parameters.Add(p));
    var reader = command.ExecuteReader(); // <- ERROR
    if (reader.HasRows)
    {
        data.Load(reader);
    }
    reader.Close();

    var maps = Maps.ByProperties(properties).ToList();
    var results = data.Rows.Cast<DataRow>().Select(r => New(r, maps)).ToList();
    return results;
}

an here the command object: command object

4
  • 1
    The parameter name of the parameter object is NULL, I'm guessing that's the problem. Commented Nov 4, 2015 at 14:08
  • Thanks, You are great! Commented Nov 4, 2015 at 14:14
  • You're welcome. I added it as an answer below, please accept it, so this question can be wrapped up. Commented Nov 4, 2015 at 15:36
  • The mistake was, I used a wrong constructor [new SQLiteParameter(type, parameterName) { Value = parameterValue}] instead of new SQLiteParameter(type, parameterValue) {ParameterName = parameterName} in an other part of code. Commented Nov 5, 2015 at 8:44

1 Answer 1

1

The parameter name of the parameter object is NULL, I'm guessing that's the 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.