user2895164 user2895164 - 1 year ago 109
Android Question

Android Delete All record SQLite

I am new to Android with a button and I would like to delete all the records in the Sqlite db according to the year chosen by the spinner.
That is, if I choose the spinner, 2013, the pressure of the Button must be eliminated all the data entered in that year. Obviously in the db there is a field of type TEXT in which is inserted the date in the format "yyyy-mm-dd".

public void onClick(DialogInterface dialog, int which) {

SQLiteDatabase db= mHelper.getWritableDatabase();
db.delete(MyTable.TABLE_NAME, null, null);


Answer Source

The second and third parameters to the delete() method on SQLiteDatabase allow you to specify a SQL WHERE clause (and values for positional parameters) to constrain which records get deleted.

You, instead, are passing null.

Replace the null values with a valid WHERE clause (e.g. "your_column_name_goes_here LIKE ?") and String[] array of positional parameters (containing the value to replace the ?).

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download