繁体   English   中英

使用sqllite数据库不删除数据

[英]Data not delete using sqllite database

如何通过android使用sqlite数据库删除特定数据。

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

错误:找不到索引

您必须确定数据是否存在于 sqlite 数据库中。

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

现在像这样修改你的代码......

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

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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