I want to be able to delete a specific column in my SQLite Database.
I have tried to pass the id of the column as the whereClause
, but i keep getting an error saying that the whereClause
needs a string value.
I have combed SO for a solution but have not found anything that answers my question. I have also tried to google search and have written my question many different ways, but to no avail.
Here is my code
Delete Button
public void toDeleteNote(View view) {
DBHelper dbHelper = new DBHelper(this);
int deletedRows = dbHelper.deleteData(selectedID);
if (deletedRows > 0){
Toast.makeText(getBaseContext(), selectedName + " deleted successfully", Toast.LENGTH_LONG).show();
} else {
Toast.makeText(getBaseContext(), "Something went wrong!", Toast.LENGTH_LONG).show();
}
Intent intent5 = new Intent(EditData.this, MainActivity.class);
startActivity(intent5);
}
}
DBHelper Delete method
public int deleteData(int id){
String ID = String.valueOf(id);
SQLiteDatabase database = this.getWritableDatabase();
return database.delete(TABLE_NAME, _id + " = ?",new String[]{ID});
CREATE TABLE
@Override
public void onCreate(SQLiteDatabase db) {
String createTable = "CREATE TABLE " + TABLE_NAME + "(_id INTEGER PRIMARY KEY AUTOINCREMENT, " + MAP_NO + " INTEGER, " + LOCATION + " TEXT, " + DATE + " INTEGER, " + NOTATHOMES + " TEXT)";
db.execSQL(createTable);
}
If you need any more informantion, please feel free to ask.