update sql database with ContentValues and the update-method

You’re using the update function wrong. It should be like this:

String where = "id=?";
String[] whereArgs = new String[] {String.valueOf(id)};

db.update(DATABASE_TABLE, dataToInsert, where, whereArgs);

The Strings in the whereArgs array gets substituted in for each ‘?’ in the where variable.

ie. if you had where = “name=? AND type=? then the first ‘?’ would get replaced by whereArgs[0] and the second by whereArgs[1].

Leave a Comment