2012-03-20 42 views
2

有人可以解釋刪除的實際工作原理,因爲文檔沒有提供足夠的幫助。我想要做的是從我的表中刪除所有行,其中的日期與我在刪除方法中提供的日期相匹配。適用於Android的SQLite刪除

這是我已經試過:

SQLiteDatabase db = appts.getWritableDatabase(); 

    String whereclause = "WHERE DATE = "; 

    long seldate = calendar.getDate()/1000; 
    String datestodelete = new java.text.SimpleDateFormat("dd/MM/yyyy").format(new java.util.Date (seldate*1000)); 

    db.delete(TABLE_NAME, whereclause, datestodelete); 

但它說接受該方法字符串字符串字符串心不是,我會放什麼呢?

回答

8

第三參數應該是String[]型的,而不是String

public int delete (String table, String whereClause, String[] whereArgs) 

tablewhereClause,和whereArgs應如下格式化:

table = "table_name"; 
whereClause = "col1 = ? AND col2 = ?"; 
whereArgs = new String[] { date1, date2 }; 

換句話說,在值String[]將取代您的whereClause中的?。另外請注意,您應該在whereClause開頭忽略WHERE(當Android執行刪除操作時,會自動添加)。

+0

正如我所說我已閱讀此內容,但它並不清楚。我知道在哪裏把我的表名稱,但我不知道如何形成我的whereClause或什麼意思通過要求字符串[] – nexus490 2012-03-20 03:16:37

+0

剛剛編輯我的帖子,希望更清楚 – 2012-03-20 03:22:49

+0

好吧,到達那裏慢慢,字符串[ ]爲這種方法服務? – nexus490 2012-03-20 03:26:02