SQLITE Android删除查询已执行但未删除该值。它在APP发布时再次显示

时间:2017-07-26 06:15:09

标签: android sqlite android-sqlite delete-row

这是我的代码

public void deleteNote(String tv){

    SQLiteDatabase db = this.getWritableDatabase();
    db.execSQL("DELETE FROM TBT WHERE name='" + tv +"'");
    db.close();
}

图片:

enter image description here

3 个答案:

答案 0 :(得分:1)

您应该使用db.delete

public void deleteNote(String tv){
        SQLiteDatabase db = this.getWritableDatabase();
        db.delete(DATABASE_TABLE, KEY_NAME + "=?", new String[]{tv});
    }

答案 1 :(得分:0)

尝试这样的事情

public Integer deleteProduct (String id) {
        SQLiteDatabase db = this.getWritableDatabase();

        return db.delete(PRODUCT_TABLE_NAME,
                COLUMN_PRODUCT_ID +"=?", new String[]{id});
    }

答案 2 :(得分:0)

您需要调用 delete() SQLiteDatabase 方法从表中删除记录,请尝试以下示例。

// Deleting record
public void deleteNote(String tv) {
   SQLiteDatabase db = this.getWritableDatabase();
   db.delete(TABLE_NAME, COLUMN_NAME + " = ?", new String[]{tv});
   db.close();
}