1

I tried to make DeleteEvent(),but it doesn't work. where do i need to change the code?

This is an Android Studio java code.

public class DBStructure {enter code here
    public static final String DB_NAME =    "EVENTS_DB";
    public static final int DB_VERSION = 1;
    public static final String EVENT_TALE_NAME = "eventstable";
    public static final String EVENT = "event";
        public static final String TIME = "time";
    public static final String DATE = "date";
    public static final String MONTH = "month";
    public static final String YEAR = "year";

}

And this my DeleteEvent()

public void DeleteEvent(String event, String time, String date, String month, String year, SQLiteDatabase database){
    ContentValues contentValues = new ContentValues();
    contentValues.remove(DBStructure.EVENT);
    contentValues.remove(DBStructure.TIME);
    contentValues.remove(DBStructure.DATE);
    contentValues.remove(DBStructure.MONTH);
    contentValues.remove(DBStructure.YEAR);
    database.delete(DBStructure.EVENT_TALE_NAME, "?=? AND ?=?",
            new String[] {DBStructure.EVENT, event, DBStructure.TIME, time});
}
1
  • can u show the code of usage of DeleteEvent() ? Commented Jul 3, 2019 at 5:46

1 Answer 1

1

You don't need ContentValues to use the delete() method:

public void DeleteEvent(String event, String time, String date, String month, String year, SQLiteDatabase database){
    database.delete(
        DBStructure.EVENT_TALE_NAME, 
        DBStructure.EVENT + " = ? AND " + DBStructure.TIME + " = ? AND " + DBStructure.DATE + " = ? AND " + 
        DBStructure.MONTH + " = ? AND " + DBStructure.YEAR + " = ?",
        new String[] {event, time, date, month, year}
    );
}

In the 2nd argument you construct the WHERE clause and the 3d contains in the form of a string array the parameters which will replace the placeholders ?.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.