2011-08-05 24 views
2

首先我創建一個輔助類數據庫如下:Android的SQL刪除行不工作

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. 

以後,我插入的數據,我已經看到了它的工作原理是在一個TextView顯示插入的數據。我需要刪除一行時出現問題。

我可以用

db.delete(TABLE, null , null);刪除一切(我又可以看到這個作品)

但是如果我將其更改爲刪除單行如

db.delete(TABLE, "_id" + Index, null);其中,例如INT指數= 4;

什麼也沒有發生,我得到沒有錯誤,沒有刪除。

任何人都可以幫助爲什麼發生這種情況?

回答

1

嘗試

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

感謝您的幫助,但是這也不起作用。 – user485175

2
SQLiteDatabase db = this.getWritableDatabase();  
db.delete(TABLE_CONTACT, _ID + "=" + _id, null); 
db.close(); 
0

db.delete(表中, 「_id =」 +指數,NULL);