delete row while extends SQLiteOpenHelper
-
14-03-2021 - |
Question
i was write the method to delete row....but, i don't know why, i can't delete row.... this is my the method...
public void clearDatabase() {
openDataBase();
try {
int id=0;
Cursor c = myDB.rawQuery("Select id from " + tablename +" asc", null);
if (c.getCount() > 22) {
c.moveToFirst();
id = c.getInt(0);
for(int i = 0;i<11;i++){
int x = id+i;
myDB.execSQL("delete from "+tablename +" where id = "+x , null);
}
}
else
c.close();
closedb();
} catch (SQLiteException ex) {
ex.printStackTrace();
}
}
and this is the logcat: 12-13 12:10:57.073: ERROR/AndroidRuntime(327): java.lang.RuntimeException: Unable to start activity ComponentInfo{com.parser/com.parser.parse}: java.lang.IllegalArgumentException: Empty bindArgs
Please help me!...Thanks before1
Solution
I use
public void deleteEntry(long lRow) {
ourDatabase.delete(DATABASE_TABLE, KEY_ROWID + "=" + lRow, null);
}
in my SQLite DB to delete a row, where lRow is passed from my view activity.
EDIT
and here is my delete button in the view activity
String dRow = etSQLvRec.getText().toString();
long lRow = Long.parseLong(dRow);
DBase db1 = new DBase(this);
try {
db1.open();
db1.deleteEntry(lRow);
db1.close();
} catch (Exception e) {
String error = e.toString();
Dialog d = new Dialog(this);
d.setTitle("Cannot Delete");
TextView tv = new TextView(this);
tv.setText(error);
d.setContentView(tv);
d.show();
}
etSQLvRec is a TextView that displays the _id of the record I'm viewing, I pass it so it deletes the record I'm viewing.
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow