Reputation: 4242
In my app, I am using an SQLite database for storing values. I want to delete some records in the database using the WHERE
clause.
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?
Upvotes: 1
Views: 296
Reputation: 2024
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;
}
Upvotes: 2
Reputation: 37
Use the code below:
public void Delete_Bus(String bus_num)
{
SQLiteDatabase db=this.getWritableDatabase();
db.execSQL("DELETE FROM "+TABLE_BUS+" WHERE "+"user_login_name"+"='"+user_login_name+"'");
db.close();
}
Upvotes: 1