使用C#操作SQLite时遇到一个错误:Insufficient parameters supplied to the command,网上搜索原因大多都是复制粘贴的,说是参数命令的长度太长,看到这个结论首先就判定这个人的编程经验是零,他可能都不知道什么是语言编译器。还有的是说把参数换成?这种方式,等等。

code = Unknown (-1), message = System.Data.SQLite.SQLiteException (0x80004005): unknown error
Insufficient parameters supplied to the command
   在 System.Data.SQLite.SQLiteStatement.BindParameter(Int32 index, SQLiteParameter param)
   在 System.Data.SQLite.SQLiteStatement.BindParameters()
   在 System.Data.SQLite.SQLiteCommand.BuildNextCommand()
   在 System.Data.SQLite.SQLiteCommand.GetStatement(Int32 index)
   在 System.Data.SQLite.SQLiteDataReader.NextResult()
   在 System.Data.SQLite.SQLiteDataReader..ctor(SQLiteCommand cmd, CommandBehavior behave)
   在 System.Data.SQLite.SQLiteCommand.ExecuteReader(CommandBehavior behavior)
   在 System.Data.SQLite.SQLiteCommand.ExecuteNonQuery(CommandBehavior behavior)
   在 System.Data.SQLite.SQLiteCommand.ExecuteNonQuery()
   在 Dapper.SqlMapper.ExecuteCommand(IDbConnection cnn, CommandDefinition& command, Action`2 paramReader)
   在 Dapper.SqlMapper.ExecuteImpl(IDbConnection cnn, CommandDefinition& command)
   在 Dapper.SqlMapper.Execute(IDbConnection cnn, String sql, Object param, IDbTransaction transaction, Nullable`1 commandTimeout, Nullable`1 commandType)

下面说的下正确的错误原因:
这个错误是由Dapper传参数引起的。可能你的代码如下:

try
            {
                string sql = @"REPLACE into configure(code,name,status,val,updatedate,updater,remark)
VALUES(@code,@name,@status,@val,@updatedate,@updater,@remark);";

                using (SQLiteConnection conn = new SQLiteConnection(_connectionStr))
                {
                    conn.Open();
                    conn.Execute(sql, model);
                }
            }
            catch (Exception ex)
            {
                _logger.Error($"插入或更新configure表出现异常,ex:{ex.Message}");
            }

model是我们的参数,是一个强类型的类。你的写法如下:

Class PModel{
public string Name;
public uint Age;
}

正确的写法应该是:

Class PModel{
public string Name{get;set;}
public uint Age{get;set;}
}

这个叫少了类属性的索引器。这样写看一看你的错误修复了吗?