开发者

Deleting from SQLite

Hy!

I always get e sql error. I log the id of the choosen item and then i want to remove it from the ListView and from the db

My code:

public boolean onItemLongClick(final AdapterView<?> arg0, final View arg1,
    final int arg2, long arg3) {
        final Pizza pizza = (Pizza)arg0.getItemAtPosition(arg2);
        Log.e("xxx",String.valueOf(pizza.id));
        AlertDialog.Builder builder = new AlertDialog.Builder(Main.this);
        builder.setMessage("Are you sure you to delete " + pizza.title + "?")
       .setCancelab开发者_运维技巧le(false)
       .setPositiveButton("Yes", new DialogInterface.OnClickListener() {
        public void onClick(DialogInterface dialog, int id) {
            aa.notifyDataSetChanged();
            list.remove(pizza);
            aa = new CustomAdapter(Main.this, R.layout.customlistitem,list);
            lv.setAdapter(aa);
                myDB = Main.this.openOrCreateDatabase(MY_DB_NAME, MODE_PRIVATE, null);
                myDB.execSQL("DELETE FROM "+MY_DB_TABLE+ " WHERE ID="+pizza.id);
       }

Log:

xxx is 1 so the id of the pizza is 1

10-03 09:23:13.135: ERROR/AndroidRuntime(640): android.database.sqlite.SQLiteException: no such column: ID: DELETE FROM Pizza WHERE ID=1


Preferred way to delete from SQLLite DB is with db.delete() Something like: db.delete(DBAdapter.TableName, "Id=?", new String[] { pizza.id });


You sure your pizza ID column named "ID"? android sqlite database already has a column nameed "_id" as the ID field.


android.database.sqlite.SQLiteException: no such column: ID: DELETE FROM Pizza WHERE ID=1

Error indicates that there is No Column named ID, so ensure that the Name of Pizza id is ID or something else.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜