-2

While deleting record through primary key, primary key get null value and record doesn't deleted.

Please look in to my code,

 dataBase.delete(DbHelper.TABLE_PARKSAL_TABLELIST, DbHelper.PARKSALE_PrimeryID+ "=" + primarykeytableid, null);

I want to delete whole row data with primary key as well. How to fix it? Thanks in advance.

Sunisha Guptan
  • 1,555
  • 17
  • 44
Shuchi Sheth
  • 219
  • 2
  • 13

2 Answers2

0

Checkout that you are passing each parameters and is not null like primarykeytable id cannot be null.

Or you can try this

db.delete(DbHelper.TABLE_PARKSAL_TABLELIST, DbHelper.PARKSALE_PrimeryID+"=?", new String[]{Integer.toString(id)});
0

If you want to delete the row with key is empty or null or your given value, We can delete the row using following,

String whereClause = DbHelper.PARKSALE_PrimeryID + " = ? OR " // For the value which you give
        + DbHelper.PARKSALE_PrimeryID + " = ? OR " // For empty values
        + DbHelper.PARKSALE_PrimeryID + " IS NUL"; // For Null values
String[] whereArr = new String[] {
        primarykeytableid, "''"
};

dataBase.delete(DbHelper.TABLE_PARKSAL_TABLELIST, whereClause, whereArr);
Muthukrishnan Rajendran
  • 11,122
  • 3
  • 31
  • 41