如何通过android中的主键删除记录

时间:2017-06-07 08:58:00

标签: android primary-key android-database

通过主键删除记录时,主键获取空值并且记录不会被删除。

请查看我的代码,

 dataBase.delete(DbHelper.TABLE_PARKSAL_TABLELIST, DbHelper.PARKSALE_PrimeryID+ "=" + primarykeytableid, null);

我也希望用主键删除整行数据。怎么解决?提前谢谢。

2 个答案:

答案 0 :(得分:0)

检查您是否传递了每个参数,并且不像null,而且不能为null。

或者你可以试试这个

db.delete(DbHelper.TABLE_PARKSAL_TABLELIST, DbHelper.PARKSALE_PrimeryID+"=?", new String[]{Integer.toString(id)});

答案 1 :(得分:0)

如果要删除键为空的行或空或您的给定值,我们可以使用以下内容删除该行,

String whereClause = DbHelper.PARKSALE_PrimeryID + " = ? OR " // For the value which you give
        + DbHelper.PARKSALE_PrimeryID + " = ? OR " // For empty values
        + DbHelper.PARKSALE_PrimeryID + " IS NUL"; // For Null values
String[] whereArr = new String[] {
        primarykeytableid, "''"
};

dataBase.delete(DbHelper.TABLE_PARKSAL_TABLELIST, whereClause, whereArr);