Update all rows in a column to new value

℡╲_俬逩灬. 提交于 2019-12-23 12:09:39

问题


Apologies, I am sure this has been asked plenty of times but I have searched around for a good example and haven't been able to find one.

I'd like to run a method to insert a value into a particular column for all rows in a table. To give you an idea of the methods and queries I'm working with, this is my working update method for my Students table:

public void updateStudent(long id,String name, String age, String points,
        String teachernote,byte[] blob) {
    ContentValues cv = new ContentValues();
    cv.put(Students.STUDENT_NAME, name);
    cv.put(Students.STUDENT_AGE, age);
    cv.put(Students.STUDENT_POINTS, points);
    cv.put(Students.TEACHERNOTE, teachernote);
    cv.put(Students.IMAGE,blob);

    db = sqlHp.getWritableDatabase();
    db.update(Students.TABLE, cv, Students.STUDENT_ID+"="+ id, null);
    db.close();
}

I'm after a query to update STUDENT_POINTS for all rows. Any help would be much appreciated, thank you.


回答1:


If you want to update all rows you have to remove the where clause. In your example you should remove Students.STUDENT_ID+"="+ id, from db.update(Students.TABLE, cv, Students.STUDENT_ID+"="+ id, null);



来源:https://stackoverflow.com/questions/16173473/update-all-rows-in-a-column-to-new-value

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!