简体   繁体   中英

Data not delete using sqllite database

How to delete specific data using sqlite database via android.

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

error: index not found

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});
}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM