2

Firstly I am creating a Database in a helper class as follows:

public void onCreate(SQLiteDatabase db) {
    String sql = "create table " + TABLE + "( " + ID
            + " integer primary key autoincrement, " + FIELD1 + " text, "
            + FIELD2 + " text);";
    Log.d("EventsData", "onCreate: " + sql);
    db.execSQL(sql);
}// Where public static final String ID = "_id"; ect.

I have then inserted data and I have seen it works by displaying the inserted data in a TextView. My problems come when I need to delete a row.

I can deleted everything by using

db.delete(TABLE, null , null); (again I can see that this works)

However if I change it to deleted a single row such as

db.delete(TABLE, "_id" + Index, null); Where for example int Index =4;

nothing happens, I get no errors and no delete.

Can anyone help with why this happens?

3 Answers 3

2
SQLiteDatabase db = this.getWritableDatabase();    
db.delete(TABLE_CONTACT, _ID + "=" + _id, null);
db.close();
Sign up to request clarification or add additional context in comments.

Comments

1

Try

db.delete(TABLE, "_id = ?", new String[] { "" + Index });

Comments

0

db.delete(TABLE, "_id=" + Index, null);

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.