//删除所有数据代码,可以实现
public long DeleteAllSms() {
   open();
   return db.delete(DB_TABLE_COURSE,null,null);
}//删除一项数据,却不能,函数始终返回0
public int removeSubject(int index) {
open();
String where = KEY_ID+"="+index;
return db.delete(DB_TABLE_COURSE,where, null);

}大家觉得可能是哪方面的问题呢,有没有遇到这问题的兄弟姐妹,真心求教!!!

解决方案 »

  1.   

    你的表结构是?
    key_id 确认存在?
      

  2.   

    我的表结构是这样的:
    private static final String TB_CREATE_COURSE = "CREATE TABLE "+
    DB_TABLE_COURSE+" ("+KEY_ID+" Integer primary key autoincrement,"+

    KEY_DAY_OF_WEEK +" text not null," +
    KEY_START_WEEK+" text not null,"+
    KEY_END_WEEK +" text not null,"+
    KEY_TEACHER_NAME+" text not null,"+
    KEY_COURSE_NAME +" text not null,"+
    KEY_TEACH_PLACE+" text not null,"+
    KEY_CURRENT_WEEK+" text not null,"+

    KEY_START_LESSION_TIME+" text,"+
    KEY_END_LESSION_TIME +" text);";
      

  3.   

    //具体的删除代码如下将removeSubject直接改为DeleteAllSms()却可以删除所有的,为什么啊,难道是这个列表项事件写得有问题?
    @Override
    public void onItemClick(AdapterView<?> arg0, View arg1, int arg2,
    long arg3) {
    selectedItem = arg2;
    new AlertDialog.Builder(AnimationTest.this).setIcon(R.drawable.icon).
    setTitle("课程设置").setPositiveButton("删除课程",
    //创建DialogInterface.OnClickListener对象实例,当单击按钮时调用onClick方法
    new DialogInterface.OnClickListener() {

    @Override
    public void onClick(DialogInterface dialog, int which) {
    System.out.println(dbAdapter.removeSubject(selectedItem)+"返回值");
    if(dbAdapter.removeSubject(selectedItem)>0) {
    simpleAdapter.notifyDataSetChanged();
    listView.setAdapter(simpleAdapter);
    Toast.makeText(AnimationTest.this, "删除成功", Toast.LENGTH_SHORT).show();
    }
    else {
    System.out.println("删除不成功");
    System.out.println(selectedItem);
    }

    }
    }).setNegativeButton("更改课程",
                         new DialogInterface.OnClickListener() {

    @Override
    public void onClick(DialogInterface dialog, int which) {

    }
    }).create().show();

    }
    });
      

  4.   

    留意一下你的KEY_ID变量是什么值。iIndex是否存在。
      

  5.   

    断点一下 看看执行的sql是什么吧
    一目了然
      

  6.   

    你说的很对,就是KEY_ID的值是什么