In my activity I have a spinner with data taken from SQLite db by this query:
private List<String> ottieniAnni(){
List<String> result = new LinkedList<String>();
SQLiteDatabase db = new BHelper(this).getReadableDatabase();
String sql = "SELECT DISTINCT strftime('%Y',"+GTable.DATE+") FROM "+GTable.TABLE_NAME;
Cursor c = db.rawQuery(sql, null);
while (c.moveToNext()){
result.add(c.getString(0));
}
db.close();
return result;
}
Now through button, I want to delete all records in the year chosen by the user. I used the method db.delete (), but so will delete all the records. Should I set a parameter but do not know how to do it:
SQLiteDatabase db= mHelper.getWritableDatabase();
db.delete(GiornateTable.TABLE_NAME, null, null );
db.close();
Try like
SQLiteDatabase db= mHelper.getWritableDatabase();
int rowcount = db.delete(GiornateTable.TABLE_NAME,
"GIVE YOUR COLUMN NAME" + "=?",
new String[] { "GIVE YOUR VALUE" });
Log.d("No of record deleted",String.valueOf(rowcount));
您可以使用与select相同的语法,仅用于删除
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.