在 Sqlite 中删除行 table

Deleting row in Sqlite table

我知道它已被问过一百万次,但我仍然无法让它工作。我试图从我的 sqlite 数据库中删除一行,但我一直收到错误。我确定这与我的语法有关,但我无法获得正确的语法。

这是我的删除方法

public void deleteRouteNote(int notePosition){
    SQLiteDatabase db = getWritableDatabase();

    db.delete(TABLE_ROUTE_NOTE, COLUMN_NOTE + COLUMN_ROUTE_NOTE_POSITION + "where" + COLUMN_ROUTE_NOTE_POSITION + "=" + notePosition, null);

    db.close();

以及我遇到的错误

android.database.sqlite.SQLiteException: no such column: routeNotewhererouteNotePosition (code 1): , while compiling: DELETE FROM route_note WHERE routeNotewhererouteNotePosition=9

感谢您的帮助!!

编辑:

这是我插入数据的方式

  /////Add route note row to table
public void addRouteNote(RouteNote routeNote){
    ContentValues values = new ContentValues();
    values.put(COLUMN_NOTE, routeNote.get_routeNote());
    values.put(COLUMN_ROUTE_NOTE_POSITION, routeNote.get_routeNotePosition());
    SQLiteDatabase db = getWritableDatabase();
    db.insertWithOnConflict(TABLE_ROUTE_NOTE , null, values, SQLiteDatabase.CONFLICT_REPLACE);
    db.close();
}

试试这个

db.delete(TABLE_ROUTE_NOTE, COLUMN_ROUTE_NOTE_POSITION + " = " + notePosition, null)

From the docs,

table String: the table to delete from

whereClause String: the optional WHERE clause to apply when deleting. Passing null will delete all rows.

whereArgs String: You may include ?s in the where clause, which will be replaced by the values from whereArgs. The values will be bound as Strings.

所以根据这个你的删除子句可能是这样的,

db.delete(TABLE_ROUTE_NOTE,COLUMN_ROUTE_NOTE_POSITION + "=? ,new String[]{notePosition});