user2306201
user2306201

Reputation: 41

Not Able to delete a record

My Function For Delete Record:

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

And my code where I'm trying to delete a record:

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();

}

I'm not getting any error but record is not deleted. It remains as it is. Please help me I've already referred many answers, but still not done with this. Thank You

Upvotes: 0

Views: 60

Answers (1)

CL.
CL.

Reputation: 180240

You are converting the ID value into a string. There is no record whose ID is a string with that value.

Plain integers have no problems with formatting or SQL injection, so it is safe to embed them directly into the query string:

sqLiteDatabase.delete(KK_AIRLINEBOOK, KEY_ID + " = " + uid);

Upvotes: 1

Related Questions