這可能是一個愚蠢的問題,每當我從服務器獲取記錄需要刪除表中的舊記錄,並需要將新值插入到該表中,我該怎麼做!到目前爲止我所嘗試的是!如何刪除表中的現有記錄並在sqlite中插入新值?
public void DashInsertorUpdate(DashBoardModel dashobjj){
String query=" SELECT * FROM " + DashBoardModel.DashBoardTable + " WHERE " + DashBoardModel.DashBoardLable +"";
Cursor c = db.rawQuery(query, null);
if (c.moveToFirst()) {
DeleteDashboard(dashobjj);
} else {
InsertDashBoardLeadBySource(dashobjj);
}
}
public void DeleteDashboard(DashBoardModel modelobj){
db.execSQL(" DELETE FROM " + DashBoardModel.DashBoardTable + " WHERE " + DashBoardModel.DashBoardLable + "= '" + modelobj.getLabel() + "'");
}
但它沒有刪除現有的記錄我怎麼能做到這一點,任何人都可以幫助我!
db.execSQL(「delete from」+ TABLE_NAME); –
db.delete(TABLE_NAME,null,null); –
select語句在做什麼?您使用WHERE子句,但是條件是什麼,並且您確定從該查詢獲得結果? –