JJkk JJkk - 25 days ago 22
Android Question

Android SQLite database delete

I want to delete the all rows by dates. In the table I have the rows with this format:

2014-01-01
. Now, I want to delete the all rows by date range.
I have created this method, but I believe there is a syntax error:

public void deleteAllEntrate_e_uscite(View v) {
SQLiteDatabase db = mHelper.getWritableDatabase();
db.delete(MyTable.TABLE_NAME, MyTable.DATA + "BETWEEN" +dateAndTime+ "AND" +dateAndTime1, null);
db.close();
finish();

}

Answer

You need to separate your keywords:

MyTable.DATA + "BETWEEN" +dateAndTime+ "AND" +dateAndTime1

you need spaces AND you need apostrophes, since your dates are strings:

MyTable.DATA + " BETWEEN '" +dateAndTime+ "' AND '" +dateAndTime1 +"'"
Comments