Updating a row in a table
suggest change// You need a writable database to update a row final SQLiteDatabase database = openHelper.getWritableDatabase(); // Create a ContentValues instance which contains the up to date data for each column // Unlike when inserting data you need to specify the value for the PRIMARY KEY column as well final ContentValues values = new ContentValues(); values.put(COLUMN_ID, model.getId()); values.put(COLUMN_NAME, model.getName()); values.put(COLUMN_DESCRIPTION, model.getDescription()); values.put(COLUMN_VALUE, model.getValue()); // This call performs the update // The return value tells you how many rows have been updated. final int count = database.update( TABLE_NAME, // The table name in which the data will be updated values, // The ContentValues instance with the new data COLUMN_ID + " = ?", // The selection which specifies which row is updated. ? symbols are parameters. new String[] { // The actual parameters for the selection as a String[]. String.valueOf(model.getId()) } );
Found a mistake? Have a question or improvement idea?
Let me know.
Table Of Contents