user2696057
user2696057

Reputation: 11

Android Delete row from local database

I am trying to delete record from local database .. Where i can update the record but not able to delete the record .. I am not getting any error but still records not get deleted from local database.. Here is the code..

db.deleteReading(complaintNo);

public void deleteReading(String id) {

    SQLiteDatabase db = this.getWritableDatabase();
    db.delete(TABLE_READINGS, COLUMN_COMPLAINT_NO  +"="+ id, null)  ;  //COLUMN_COMPLAINT_NO is available in my readings table
    db.close();

}

Please guide me where i am getting wrong

Upvotes: 0

Views: 142

Answers (2)

user2952423
user2952423

Reputation: 121

i think the problem is in your query..

int temp=db.delete(TABLE_READINGS, COLUMN_COMPLAINT_NO  +"="+ id, null)  ;
Log.d("query value",temp);

instead of this try this

int temp=db.delete(TABLE_READINGS, COLUMN_COMPLAINT_NO  +"='"+ id+"'", null)  ;
///////// print it in logcat
Log.d("query value",temp);

Upvotes: 0

PaF
PaF

Reputation: 3477

The problem is that you're not enclosing the string in single quotes:

db.delete(TABLE_READINGS, COLUMN_COMPLAINT_NO  +"='"+ id + "'", null);

Or you can use the more common method, and pass the string as a "where arg":

db.delete(TABLE_READINGS, COLUMN_COMPLAINT_NO  +"=?", new String[] {id});

Upvotes: 3

Related Questions