SQLite的误差参数不足在Mono.Data.Sqlite.SqliteStatement.BindParameter提供给命令 [英] SQLite error Insufficient parameters supplied to the command at Mono.Data.Sqlite.SqliteStatement.BindParameter

查看:582
本文介绍了SQLite的误差参数不足在Mono.Data.Sqlite.SqliteStatement.BindParameter提供给命令的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个简单的INSERT语句中的表上MonoDroid SQLite数据库。

当插入到数据库中,它说

  

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

我觉得这是任何一个错误,或者错误信息误导。因为我只有5个参数,我提供了5个参数,所以我看不出这是正确的。

我的code是低于,任何帮助将是很大的AP preciated。

 尝试
{
    使用(VAR连接=新SqliteConnection(的ConnectionString))
    {
        connection.Open();
        使用(VAR命令= connection.CreateCommand())
        {
            command.CommandTimeout = 0;
            command.CommandText =INSERT INTO [用户](UserPK,姓名,密码,类别,ContactFK)VALUES(@UserPK,@Name,@Password,@Category,@ContactFK);
            command.Parameters.Add(新SqliteParameter(@名称,有));
            command.Parameters.Add(新SqliteParameter(@密码,有));
            command.Parameters.Add(新SqliteParameter(@ Cateogry,));
            command.Parameters.Add(新SqliteParameter(@ ContactFK,的DBNull.Value));
            command.Parameters.Add(新SqliteParameter(@ UserPK,DbType.Guid){值= Guid.NewGuid()});
            VAR的结果= command.ExecuteNonQuery();
            收益率=结果> 0;
        }
    }
}
赶上(例外的例外)
{
    LOGERROR(例外);
}
 

解决方案

您拼写 @Category 在INSERT语句是添加的参数不同。 你有:

  command.Parameters.Add(新SqliteParameter(@ Cateogry,));
                                           ^^^^^^^^^^^
                                           //@类别
 

当它应该是:

修改你的语句:

  command.Parameters.Add(新SqliteParameter(@范畴,));
 

I have a simple insert statement to a table in an SQLite database on MonoDroid.

When inserting to the database, it says

SQLite error Insufficient parameters supplied to the command at Mono.Data.Sqlite.SqliteStatement.BindParameter

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);
}

解决方案

Your spelling for @Category in INSERT statement is different from added parameter. You have:

command.Parameters.Add(new SqliteParameter("@Cateogry", ""));
                                           ^^^^^^^^^^^
                                           //@Category

Where it should be:

Modify your statement to:

command.Parameters.Add(new SqliteParameter("@Category", ""));

这篇关于SQLite的误差参数不足在Mono.Data.Sqlite.SqliteStatement.BindParameter提供给命令的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆