Krish Krish - 9 months ago 20
Android Question

Not able to delete SQLite records using WHERE clause

In my app, I am using an SQLite database for storing values. I want to delete some records in the database using the


Here is the function that I wrote:

public Cursor deleteSomeDetails(String user_login_name, String product_code,
SQLiteDatabase db) {
Cursor cursor = db.rawQuery("delete from "
+ RaisePoProductDetails.NewUSerInfo.TABLE_NAME
+ " where user_login_name = '"
+ user_login_name + "' and productcode ='"
+ product_code + "'", null);

return cursor;

The records are still not deleting. Am I doing something wrong? Any suggestions?


Try this:

public boolean deleteSomeDetails(SQLiteDatabase db, String user_login_name, String product_code) {
    return db.delete(RaisePoProductDetails.NewUSerInfo.TABLE_NAME, "user_login_name=? and productcode=?", new String[] {user_login_name, product_code}) > 0;