Android: Count And Delete Rows From Sqlite
I want to delete some records from my database tables, for example table A and table B. Both table A and table B has a column name sycn_status. I want to delete only those records
Solution 1:
try this
db.execSQL("DELETE FROM "+ DATABASE_TABLE_DAILY_ATTENDANCE +" WHERE "+KEY_ATTENDANCE_SYN_STATUS ='C');
UPDATE:
As requested in one of the comments, the problem was with statement which is executed.
"DELETE FROM "+ DATABASE_TABLE_DAILY_ATTENDANCE +" WHERE KEY_ATTENDANCE_SYN_STATUS ='C'"
In the above statement SQLite will not be able to recognize the string as valid.
DATABASE_TABLE_DAILY_ATTENDANCE is a string value which does not require double quotes around it.
KEY_ATTENDANCE_SYN_STATUS was included within double quotes, but its already a string value, so moving it out of double quotes.
'C'" String was ending here, since the quote ended before keyword KEY_ATTENDANCE_SYN_STATUS removing the last occurance of double quotes.
Solution 2:
Please check the below code
publicvoidRemoveSyncData(){
DBHelper = new DatabaseHelper(context);
//db = DBHelper.getWritableDatabase();
db.execSQL("DELETE FROM "+ DATABASE_TABLE_DAILY_ATTENDANCE +" WHERE sync_status ='C'");
db.close();
I hope above code will work for you.
Solution 3:
Based on the exception, you made a typo in your field declaration that
KEY_ATTENDANCE_SYN_STATUS = "KEY_ATTENDANCE_SYN_STATUS".
Change it to
KEY_ATTENDANCE_SYN_STATUS = "sync_status";
Post a Comment for "Android: Count And Delete Rows From Sqlite"