1
votes

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

1
The parameter name of the parameter object is NULL, I'm guessing that's the problem. - Rik
Thanks, You are great! - Georg
You're welcome. I added it as an answer below, please accept it, so this question can be wrapped up. - Rik
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. - Georg

1 Answers

1
votes

The parameter name of the parameter object is NULL, I'm guessing that's the problem