Reputation: 13
I want to update quantity value in `sqlitedb` if item is already existed with same name which I want to insert,I execute that query but not affected on table.
This is my code to update quantity of particular item:
public int updateContact(Contact contact) {
SQLiteDatabase db = this.getWritableDatabase();
ContentValues values = new ContentValues();
values.put(KEY_NAME, contact.getName());
values.put(KEY_PRICE, contact.get_price());
values.put(KEY_QTY, contact.get_qty());
return db.update(TABLE_CONTACTS, values, KEY_QTY + "= ?", new String[] {contact.get_qty()});
}
Upvotes: 0
Views: 899
Reputation: 3134
use the name to compare not quantity.. use this code..
public int updateContact(Contact contact) {
SQLiteDatabase db = this.getWritableDatabase();
ContentValues values = new ContentValues();
values.put(KEY_NAME, contact.getName());
values.put(KEY_PRICE, contact.get_price());
values.put(KEY_QTY, contact.get_qty());
return db.update(TABLE_CONTACTS, values, KEY_NAME + "= ?", new String[] {contact.getName()});
}
Upvotes: 2