HY!
我总是得到eql错误。我记录所选项目的ID,然后我想从ListView和db
中删除它我的代码:
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,因此披萨的ID为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 :(得分:1)
从SQLLite DB中删除的首选方法是使用db.delete() 就像是: db.delete(DBAdapter.TableName,“Id =?”, new String [] {pizza.id});
答案 1 :(得分:0)
您确定您的披萨ID列名为“ID”吗? android sqlite数据库已经有一个名为“_id”的列作为ID字段。
答案 2 :(得分:0)
android.database.sqlite.SQLiteException: no such column: ID: DELETE FROM Pizza WHERE ID=1
错误表示没有列名为ID ,因此请确保 Pizza的名称ID为ID 或其他内容。