Skip to content Skip to sidebar Skip to footer

How To Delete Row With Where Clause?

i want to delete row but when i write query in deleteContact() and execute nothing happen with my database.plese help this is my code: public class ContactDatabase extends SQLit

Solution 1:

You only need the id of the table row to delete.

publicvoiddeleteContact(int pos){

db = this.getWritableDatabase();
db.delete(TABLE_NAME, ID_KEY + "= ?", newString[] {String.valueOf(pos) });
db.close();
}

Solution 2:

You can make your code cleaner as:

public int deleteContact(int id) {
    db = this.getWritableDatabase();
    return db.delete(TABLE_NAME, "_id = ?", newString[]{String.valueOf(id)});       
}

publicvoidcloseDB() {
    db = this.getReadableDatabase();
    if (db != null && db.isOpen())
            db.close();
}

Post a Comment for "How To Delete Row With Where Clause?"