Drakora
Drakora

Reputation: 118

Update all rows in a column to new value

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.

Upvotes: 4

Views: 7263

Answers (1)

Blackbelt
Blackbelt

Reputation: 157437

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);

Upvotes: 5

Related Questions