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?
SQLiteDatabase db = this.getWritableDatabase();
db.delete(TABLE_CONTACT, _ID + "=" + _id, null);
db.close();
Try
db.delete(TABLE, "_id = ?", new String[] { "" + Index });
db.delete(TABLE, "_id=" + Index, null);
精彩评论