Home > Mobile >  Data not delete using sqllite database
Data not delete using sqllite database

Time:12-19

How to delete specific data using sqlite database via android.

db.delete("tbl_rmd", "rmd_typ = ? ", new String[]{id});

error : index not found

CodePudding user response:

You must determine whether or not the data exists in the sqlite database.

 public boolean checkIfRecordExist(String tableName, String columnName, String fieldValue) {
        SQLiteDatabase database = this.getReadableDatabase();
        String Query = "Select * from "   tableName   " where "   columnName   " =? ";
        Cursor cursor = database.rawQuery(Query, new String[]{fieldValue});
        if (cursor.getCount() <= 0) {
            cursor.close();
            return false;
        }
        cursor.close();
        return true;
    }

now modify your code like this...

if (checkIfRecordExist("tbl_rmd", "rmd_typ", id)) {
    db.delete("tbl_rmd", "rmd_typ = ? ", new String[]{id});
}
  • Related