2011-10-03 138 views
0

Hy!從SQLite中刪除

我總是得到e sql錯誤。我登錄已選定項的ID,然後我想從ListView中刪除它,然後從數據庫中

我的代碼:

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 + "?") 
     .setCancelable(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); 
     } 

登錄:

xxx是1這樣的標識披薩是1

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

回答

0

您確定您的披薩ID列名爲「ID」? android sqlite數據庫已經有一個名爲「_id」的ID字段。

1

優選方式從SQLLite DB中刪除與db.delete() 是這樣的: db.delete( 「α-ID =」 DBAdapter.TableName, 新的String [] {pizza.id});

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

錯誤表明有沒有列名爲ID,因此請確保比薩ID的名稱是ID或別的東西。