Skip to content Skip to sidebar Skip to footer

Update Item In Database Without All Of The Columns Set In Contentvalues

For example, I have four columns: first_name, last_name, phone_number and picture. Somewhere in my code there's: ContentValues values = new ContentValues(); values.put(MyPerson.F

Solution 1:

To answer your question, yes you can pass just one field of data to the update and it will update that column without affecting any others.

The problem you currently have, by the looks of it, you are not telling the DB which record you want to update.

As per the update method:

public int update (String table, ContentValues values, String whereClause, String[] whereArgs)

You are passing null for the where part of the method.

If you pass a where part to the method it will update just the specific entry(s).

ContentValuesvalues=newContentValues();
values.put(MyPerson.PHONE_NUMBER, "222-222-2222");
getContentResolver().update(tedUri, values, "first_name = ?", newString[] { "tom" });

Would update anyone with the first name tom to have the phone number 222-222-2222

Solution 2:

That would work exactly as you described, only set values will be updated.

Solution 3:

You can set where clause in update function 3rd parameter

getContentResolver().update(tedUri, values, "first_name=?", newString
         [ ]{"name"});

Post a Comment for "Update Item In Database Without All Of The Columns Set In Contentvalues"