Reputation: 382
I am trying to write to SQL database on android. It works fine to create items in the database but I can't seem to be able to go back and edit them. To prove I have already hard coded an existing item ID and tried to update it but it still doesn't work, so that means there is likely something wrong with my code, or I am using it wrong. Tell me if I am missing something. This is the code that is supposed to update the database. By default, COLUMN_STATE gets a "2" and I am replacing it with a "3" here. But it just stays at 2 after this runs.
public long markMessageRead(String messageId) {
SQLiteDatabase db = this.getWritableDatabase();
ContentValues values = new ContentValues();
values.put(Messages.COLUMN_STATE, "3");
// updating row
return db.update(Messages.TABLE_NAME, values, Messages.COLUMN_MESSAGE_ID + " = ?",
new String[]{String.valueOf(messageId)});
}
Upvotes: 0
Views: 1400
Reputation: 447
Change ContentValues!
values.put(<this is columns(field)'s name in your table>, "3"); by you description > < COLUMN_STATE gets a "2" > this maybe values in your table.
Example :
ContentValues values = new ContentValues();
values.put("number", "3");
db.update(Messages.TABLE_NAME, values, Messages.COLUMN_MESSAGE_ID + " = ?",
new String[]{String.valueOf(messageId)});
another way by update :
String where = "id = 'your id'";
db.update(table, values, where, null); //where can be null
It's work the same way, if this doesn't help you,Please try to test with rawQuery.
Upvotes: 1