How to update a particular column on behalf of id in sqlite android-ThrowExceptions

Exception or error:

I want to update Flag column in sqlite table from 0 to 1 so when the data is send to server the flag update from 0 to 1. Here is my code :

Create table Code :

db.execSQL(" CREATE TABLE " + Order_Master + " ( " + KEY_Order_No + " INTEGER PRIMARY KEY AUTOINCREMENT , " + KEY_Order_Date + " DATE , " + KEY_Member_Code + " VARCHAR (200) NOT NULL , " + KEY_Table_No + " VARCHAR(100) , " +
                  KEY_WAITER_NAME + " VARCHAR (100) NOT NULL , " + KEY_HH_CODE + " VARCHAR (100) NOT NULL ," + KEY_CHILD_NAME + " VARCHAR (200) NOT NULL , " + KEY_CHILD_STATUS + " VARCHAR (2) NOT NULL , "
                  + KEY_SALES_TYPE + " VARCHAR (100) NOT NULL , " +  KEY_AMOUNT + " VARCHAR (100) NOT NULL , " + KEY_FLAG + " INTEGER DEFAULT NULL ) ; ");

Insert into table code :

public boolean insertMaster  (ContentValues contentValues)
    {
        SQLiteDatabase db = this.getWritableDatabase();

        db.insert("Order_Master", null, contentValues);
        return true;
    }

now I need to update the last column “flag” from 0 to 1. Can any one help me how can I create the update method?

How to solve:

Since you have set KEY_order_no as primary key you can use that to identify the row to update as below

db.update("Order_Master", contentValues,
      KEY_order_no + "='" + key_order_no + "'", null)

###

use this method to update value

public void updateStatus(String id , int status){

SQLiteDatabase db = this.getWritableDatabase();

ContentValues data = new ContentValues();

data.put(“status”, status);

db.update(TableName, data, “columnName” + ” = “+id , null);

}

Leave a Reply

Your email address will not be published. Required fields are marked *