update sql database with ContentValues and the update-method

后端 未结 4 1978
醉酒成梦
醉酒成梦 2020-11-30 09:55

I would like to update my SQL lite database with the native update-method of the SQLiteDatabase class of android.

ContentValues dataToInsert = new ContentVal         


        
4条回答
  •  猫巷女王i
    2020-11-30 10:42

    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].

提交回复
热议问题