2013-04-29 6 views
5

MonoDroidのSQLiteデータベースのテーブルに簡単な挿入文があります。SQLiteエラーMono.Data.Sqlite.SqliteStatement.BindParameterでコマンドに指定されているパラメータが不十分です。

データベースに挿入する際、それは、私はどちらかのバグがあると思いMono.Data.Sqlite.SqliteStatement.BindParameter

でコマンドに供給

SQLiteのエラーが不十分なパラメータを語りますエラーメッセージが誤解を招く可能性があります。私は5つのパラメータしか持っていないので、5つのパラメータを提供しているので、これが正しい方法がわかりません。

私のコードは以下の通りです。ご迷惑をおかけして申し訳ございません。 INSERT文で

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

答えて

7

@Categoryのためのあなたのスペル追加のパラメータと異なっています。あなたは持っている :それがあるべき

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

を:これはすでに正しく回答されているが、私は追加したい、詳細については

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

ありがとう、これは恥ずかしかった:) –

+0

@HasTaiar、あなたは歓迎です、これは起こります:) – Habib

1

にあなたの文を変更

この特定のSQLiteエラー文字列は、@ParametersのいずれかがINSERTステートメントで別のスペルがある場合、またはAddWithValueまたは.Add(ne w SqliteParameter ...ステートメント。

関連する問題