问题描述
我有一个简单的插入语句到 MonoDroid 上的 SQLite 数据库中的表.
I have a simple insert statement to a table in an SQLite database on MonoDroid.
当插入数据库时,它说
When inserting to the database, it says
SQLite 错误为 Mono.Data.Sqlite.SqliteStatement.BindParameter 处的命令提供的参数不足
SQLite error Insufficient parameters supplied to the command at Mono.Data.Sqlite.SqliteStatement.BindParameter
我认为要么存在错误,要么错误消息具有误导性.因为我只有 5 个参数并且我提供了 5 个参数,所以我看不出这是怎么回事.
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);
}
推荐答案
您在 INSERT 语句中对 @Category
的拼写与添加的参数不同.你有:
Your spelling for @Category
in INSERT statement is different from added parameter.
You have:
command.Parameters.Add(new SqliteParameter("@Cateogry", ""));
^^^^^^^^^^^
//@Category
它应该在哪里:
将您的陈述修改为:
command.Parameters.Add(new SqliteParameter("@Category", ""));
这篇关于SQLite 错误为 Mono.Data.Sqlite.SqliteStatement.BindParameter 处的命令提供的参数不足的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!