从sqlite数据库中删除表中的整个行

时间:2018-11-26 12:17:02

标签: android android-sqlite

我必须删除TABLE_LOCATION中的某些行。我正在使用以下代码,但并未删除。任何人都知道解决方案。

public void deleteData(String favouriteOrNot, String vaType) {
        SQLiteDatabase db = this.getReadableDatabase();
        String deleteQuery = "DELETE FROM " + TABLE_LOCATION + " WHERE " + this.FavouriteOrNot + "='" + favouriteOrNot + "' AND " + this.VaType + "='" + vaType + "';";
        db.execSQL(deleteQuery);
}

1 个答案:

答案 0 :(得分:1)

尝试这种方式

用于删除整个表格

public int DELETE_TABLE(String tableName){
        return myDataBase.delete(tableName, null, null);
    }

用于删除多个条目

public int DELETE_TABLE_WITH_SELECTION(String tableName, String selection){
return myDataBase.delete(tableName, selection, null);
    }

这里myDataBase是SQLiteDatabase。

selection = this.FavouriteOrNot + "='" + favouriteOrNot + "' AND " + this.VaType + "='" + vaType + "'";