I am trying to update a cell in a row of a data base. But the result always ends up as 0, meaning no changes where made. what am I doing wrong?
The name of the column is “Read” and all values in that column are initially 0. I need to update the value of a row’s column “Read” to integer 1.
DATABASE = openOrCreateDatabase("MAIN_DB", MODE_PRIVATE, null);
ContentValues contentValues = new ContentValues();
contentValues.put("Read", new Integer(1));
int result=0;
DATABASE.beginTransaction();
result= DATABASE.update(databasename, contentValues, "id="+db_rowid, null);
DATABASE.setTransactionSuccessful();
DATABASE.endTransaction();
DATABASE.close();
The variable db_rowid = the row id of the row i need to edit
I assume that
databasenameis actually the table name which contains your row. Thedbcolumnidis actually the row ID to update. And your table contain theidcolumn (is it primary key?). With these assumptions all should work.Finally, you can try this: