alias26
alias26

Reputation: 13

How to update a quantity with existing item in table change in android sqlite

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

Answers (1)

Sourabh Bans
Sourabh Bans

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

Related Questions