vendredi 10 juillet 2015

Update sqlite update specific row

I have got sqlite database with three rows KEY_ID = "id"; KEY_NAME = "name"; KEY_IMAGE = "image"; my DataBaseHandler.class update code look like this:

    // Updating single contact
    public int updateContact(Contact contact) {
    SQLiteDatabase db = this.getWritableDatabase();

    ContentValues values = new ContentValues();
    values.put(KEY_NAME, contact.getName());
    values.put(KEY_IMAGE, contact.getImage());

    // updating row
    return db.update(TABLE_CONTACTS, values, KEY_ID + " = ?",
            new String[] { String.valueOf(contact.getID()) });

}

My code for update only (name) without image:

        @Override
        public void onClick(View v) {

            DataBaseHandler db = new DataBaseHandler(
                    SQLiteDemoActivity.this);

            db.updateContact(new Contact(1, "Test", null));

        }
    });

This code above it will update the first record (name) to "Test" but delete the image..

i will appreciate your help...

Aucun commentaire:

Enregistrer un commentaire