0

我的删除记录功能:

public void delete_byID(int uid){
    sqLiteDatabase.delete(KK_AIRLINEBOOK, KEY_ID + "= ?", new String[] {String.valueOf(uid)});       
}

还有我试图删除记录的代码:

AlertDialog.Builder alertDialogBuilder = new AlertDialog.Builder(context);

// set title
alertDialogBuilder.setTitle("Cancel Booking");

// set dialog message
alertDialogBuilder.setMessage("Do You Really Want To Cancel Your Booking!")
.setCancelable(false)
.setPositiveButton("Yes",
new DialogInterface.OnClickListener() {

    public void onClick(DialogInterface dialog,int id) {


        // if this button is clicked, close
        // current activity
        Toast.makeText(CancelCabBooking.this, "Your
        Booking Is Canceled Now Thank You!!!!!",
        Toast.LENGTH_LONG).show();

        int uid=myPrefs.getInt("USERID", 0);
        mySQLiteAdapter.delete_byID(uid);
        Intent submit= new Intent(CancelCabBooking.this,Customerhome.class);
        startActivity(submit);
        finish();
        srno.setText("");
        charges.setText("");
        seats.setText("");
        CancelCabBooking.this.finish();

    }

}
)
.setNegativeButton("No",new DialogInterface.OnClickListener() {

    public void onClick(DialogInterface dialog,int id) {

        // if this button is clicked, just close
        // the dialog box and do nothing
        dialog.cancel();            
    }

}
);

// create alert dialog
AlertDialog alertDialog = alertDialogBuilder.create();

// show it
alertDialog.show();

}

我没有收到任何错误,但记录没有被删除。它保持原样。请帮助我,我已经提到了很多答案,但还没有完成。谢谢你

4

1 回答 1

1

您正在将 ID 值转换为字符串。没有 ID 是具有该值的字符串的记录。

纯整数在格式化或 SQL 注入方面没有问题,因此将它们直接嵌入到查询字符串中是安全的:

sqLiteDatabase.delete(KK_AIRLINEBOOK, KEY_ID + " = " + uid);
于 2013-05-06T11:49:11.143 回答