SQLite参数化更新

本文关键字:更新 参数 SQLite | 更新日期: 2023-09-27 18:12:47

有一个奇怪的场景,其中ADO。Net一直返回"SQLite错误"。命令"

"参数不足

UPDATE Query:

UPDATE [Device] SET
[DeviceSerial] = @DeviceSerial,
[RegistrationDate] = @RegistrationDate,
[RegistrationNumber] = @RegistrationNumber,
[Password] = @Password,
[Make] = @Make,
[Year] = @Year,
[OdometerStart] = @OdometerStart,
[PurchaseValue] = @PurchaseValue,
[Closed] = @Closed
WHERE [DeviceId] = @DeviceId

参数:

{ "@DeviceSerial", this.DeviceSerial }, 
{ "@RegistrationDate", this.RegistrationDate }, 
{ "@RegistrationNumber", this.RegistrationNumber }, 
{ "@Password", this.Password }, 
{ "@Make", this.Make }, 
{ "@Year", this.Year }, 
{ "@OdometerStart", this.OdometerStart }, 
{ "@PurchaseValue", this.PurchaseValue }, 
{ "@Closed", this.Closed }, 
{ "@DeviceId}", this.DeviceId } 

My DataHandler Method:

public static bool CallSqlText(string sqlStatement, Dictionary<string, object> parameters)
        {
            ConnectionCheck();
            try
            {
                var cmd = conn.CreateCommand();
                cmd.CommandType = CommandType.Text;
                cmd.CommandText = sqlStatement;
                foreach (var item in parameters)
                {
                    cmd.Parameters.AddWithValue(item.Key, item.Value);
                }
                return (cmd.ExecuteNonQuery() > 0);
            }
            catch { }
            return false;
        }

SQLite参数化更新

你有一个错别字:"@DeviceId}"应该是"@DeviceId"