1
votes

I know it's been asked a million times but I still cannot get it to work. I'm trying to delete a row from my sqlite database but I keep getting an error. I'm sure it's to do with my syntax but I cannot get the correct syntax.

heres my delete method

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();

and the error I'm getting

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

thanks for any help!!

EDIT:

Heres how I insert the data

  /////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();
}
2
please check whether you have column routeNotewhererouteNotePosition exist and the sql is correct. please post sql here. - K.Sopheak
I edited my original post to show how Im inserting which works fine. - zsh5032

2 Answers

0
votes

Try this

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

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.

So according to this your delete clause might be something like this,

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