SQLite 错误为 Mono.Data.Sqlite.SqliteStatement.BindParameter 处的命令提供的参数不足

SQLite error Insufficient parameters supplied to the command at Mono.Data.Sqlite.SqliteStatement.BindParameter(SQLite 错误为 Mono.Data.Sqlite.SqliteStatement.BindParameter 处的命令提供的参数不足)
本文介绍了SQLite 错误为 Mono.Data.Sqlite.SqliteStatement.BindParameter 处的命令提供的参数不足的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个简单的插入语句到 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 处的命令提供的参数不足的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!

本站部分内容来源互联网,如果有图片或者内容侵犯您的权益请联系我们删除!

相关文档推荐

DispatcherQueue null when trying to update Ui property in ViewModel(尝试更新ViewModel中的Ui属性时DispatcherQueue为空)
Drawing over all windows on multiple monitors(在多个监视器上绘制所有窗口)
Programmatically show the desktop(以编程方式显示桌面)
c# Generic Setlt;Tgt; implementation to access objects by type(按类型访问对象的C#泛型集实现)
InvalidOperationException When using Context Injection in ASP.Net Core(在ASP.NET核心中使用上下文注入时发生InvalidOperationException)
LINQ many-to-many relationship, how to write a correct WHERE clause?(LINQ多对多关系,如何写一个正确的WHERE子句?)