2013-04-29 76 views
5

的命令參數不足MonoDroid上的SQLite數據庫中的表有一個簡單的插入語句。SQLite錯誤提供給Mono.Data.Sqlite.SqliteStatement.BindParameter

當插入到數據庫中,它說在Mono.Data.Sqlite.SqliteStatement.BindParameter

提供至命令

SQLite的錯誤參數不足,我認爲有任何錯誤,或者該錯誤消息具有誤導性。因爲我只有5個參數,我提供了5個參數,所以我不明白這是正確的。

我的代碼如下,任何幫助將不勝感激。

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

INSERT語句中您的拼寫爲@Category與添加的參數不同。 您有:

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

,它應該是:

修改您的語句:

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

謝謝你,這是尷尬的:) – 2013-04-29 04:25:44

+0

@哈斯泰爾,不客氣,發生這種情況,:) – Habib 2013-04-29 04:26:51

1

這已經回答正確,但我想補充,進一步的信息:

如果任何@Parameters在INSERT語句中與AddWithValue或.Add(ne)拼寫不同,也可以生成此特定的SQLite錯誤字符串w SqliteParameter ...語句。