Jan de Jager
Jan de Jager

Reputation: 870

SQLite Parameterized UPDATE

Have a weird scenario where the ADO.Net keep returning "SQLite error. Insufficient parameters supplied to the command"

The 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

Parameters:

{ "@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;
        }

Upvotes: 0

Views: 2737

Answers (1)

Filip Navara
Filip Navara

Reputation: 4828

You have a typo: "@DeviceId}" should be "@DeviceId"

Upvotes: 1

Related Questions