user3245211
user3245211

Reputation: 27

delete a specific row with where clause in sqlite for android

I try to delete a specific row with where clause in sqlite for android but it not working plz any body help.

public void delete(int p){
SQLiteDatabase db = this.getReadableDatabase();
db.execSQL("delete from "+ TABLE_NAME + " WHERE " + COLUMN_ID + " ="+p);
db.close();}

Upvotes: 0

Views: 4357

Answers (2)

ChrisCarneiro
ChrisCarneiro

Reputation: 352

Try to change this this.getReadableDatabase();

to this.getWritableDatabase();

It should work.

Upvotes: 2

Zied R.
Zied R.

Reputation: 4964

try this :

public void delete(int p){
SQLiteDatabase db = this.getWritableDatabase();
db.execSQL("DELETE FROM "+ TABLE_NAME + " WHERE " + COLUMN_ID + " = "+p+"");
db.close();
}

Upvotes: 3

Related Questions