C# SQLite错误在Mono.Data.SQLite.SqliteStatement.BindParameter处为命令提供的参数不足
我在MonoDroid上的SQLite数据库中有一个简单的insert语句 当插入到数据库时,它会显示 SQLite错误在Mono.Data.SQLite.SqliteStatement.BindParameter处为命令提供的参数不足 我认为要么是错误,要么是错误信息误导。因为我只有5个参数,我提供了5个参数,所以我看不出这是怎么回事 我的代码如下,任何帮助都将不胜感激C# SQLite错误在Mono.Data.SQLite.SqliteStatement.BindParameter处为命令提供的参数不足,c#,sqlite,ado.net,xamarin.android,C#,Sqlite,Ado.net,Xamarin.android,我在MonoDroid上的SQLite数据库中有一个简单的insert语句 当插入到数据库时,它会显示 SQLite错误在Mono.Data.SQLite.SqliteStatement.BindParameter处为命令提供的参数不足 我认为要么是错误,要么是错误信息误导。因为我只有5个参数,我提供了5个参数,所以我看不出这是怎么回事 我的代码如下,任何帮助都将不胜感激 try { using (var connection = new SqliteConnection(Connect
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
的拼写与添加的参数不同。
你有:
command.Parameters.Add(new SqliteParameter("@Cateogry", ""));
^^^^^^^^^^^
//@Category
应在哪里:
将您的声明修改为:
command.Parameters.Add(new SqliteParameter("@Category", ""));
这一点已得到正确回答,但我想补充一点,以了解更多信息:
如果INSERT语句中的@Parameters与AddWithValue或.Add(新的SqliteParameter…语句)中的@Parameters拼写不同,也可以生成此特定的SQLite错误字符串。谢谢,这让人尴尬:)