It looks like your validation is comparing the quantity for the first item in the cart to the value from your rs. I don't think that this is how you want to have this setup. Instead you should be comparing the value in the db to the posted quantity value from the form, the same value that you are binding to the quantity on the add to cart. This is so that you are comparing what is attempted to be added to the cart with what is available in your db.