• Latest Code...

    Update data in SQLite using Android app


    Are you getting problems during updating data on sqlite, here is the simple way to solve this problem:

    String strFilter = "_id=" + Id;
    ContentValues args = new ContentValues();
    args.put(KEY_TITLE, title);
    myDB.update("titles", args, strFilter, null);

    Or

       ContentValues args = new ContentValues();
        args.put(columnName, newValue);
        db.update(DATABASE_TABLE, args, KEY_ROWID + "=" + rowId, null);

    Or

    db.execSQL("UPDATE DB_TABLE SET YOUR_COLUMN='newValue' WHERE id=6 ");

    Or

    String strSQL = "UPDATE myTable SET Column1 = someValue WHERE columnId = "+ someValue;

    myDataBase.execSQL(strSQL);

    Or

    updateContact()
        // 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_PH_NO, contact.getPhoneNumber());

        // updating row
        return db.update(TABLE_CONTACTS, values, KEY_ID + " = ?",
                new String[] { String.valueOf(contact.getID()) });
    }
    More: http://developer.android.com/reference/android/database/sqlite/SQLiteDatabase.html
    Happy Coding!!!

    Circle

    Most recent Elastic Search tutorials for beginner, intermediate and advance level developer, Yubraj Pokharel, in CodingWorkspace