Skip to content Skip to sidebar Skip to footer

Sqlite Cuts Off Zeros, When Updating Database

Im working with a Sqlite database in C#, when I insert my date into it, everything works fine (in the format MM.YYYY). Nevertheless when I update the database, sqlite cuts off lead

Solution 1:

Try parametrizing your query; all you should provide is date and let RDBMS do its work (formats, representation etc. included)

// using - do not forget to Dispose (i.e. free resources)
using (SQLiteCommand command = new SQLiteCommand(databaseConnection)) {
  // Do not build query, but parametrize it
  command.CommandText = 
     @"update credits 
          set lastDate = @prm_Date
        where ID = @prm_ID";

  // Parameters instead hardcoding
  //TODO: better put command.Parameters.Add(Name, Value, Type)
  command.Parameters.AddWithValue("@prm_Date", date);
  command.Parameters.AddWithValue("@prm_ID", index);

  // Non query : we don't want to return even a single value, right?
  command.ExecuteNonQuery();
}

Post a Comment for "Sqlite Cuts Off Zeros, When Updating Database"