I am trying to update my table. I have a page with just one TextBox where the user can enter a quantity, but it just doesn’t update. There’s no errors or anything. And, let’s just say that there was already ‘1’ in the column, and then I update it to say, ‘6’, then I go back to the table, that particular row has now become ‘0’. I don’t get it.
When I look at the Query String part of the url.. No matter what value I post ufing the form, it always says 0 is the query string.
Here’s what I’ve got:
var UpdateQuantityQuery = "";
if(Request.Form["IsBoxed"].AsBool() == true)
{
UpdateQuantityQuery = "UPDATE Cart SET Boxes = '" + Request.Form["quantity"].AsInt() + "' WHERE PartNumber = '" + Request.Form["PartNumber"] + "' AND IsBoxed = 'True' AND OrderId = '" + Session["OSFOID"] + "'";
database.Execute(UpdateQuantityQuery);
// Redirect back to their SHopping Cart now.
Response.Redirect("~/Account/Cart.cshtml");
}
else
{
UpdateQuantityQuery = "UPDATE Cart SET Units = '" + Request.Form["quantity"].AsInt() + "' WHERE PartNumber = '" + Request.Form["PartNumber"] + "' AND IsBoxed = 'False' AND OrderId = '" + Session["OSFOID"] + "'";
database.Execute(UpdateQuantityQuery);
// Redirect back to their SHopping Cart now.
Response.Redirect("~/Account/Cart.cshtml");
}
And the form code is:
<form method="post" action="EditQuantity.cshtml?Update=OK&PartNumber=@Request["PartNumber"]&IsBoxed=@Request["IsBoxed"]">
<fieldset>
<legend>Edit Quantity</legend>
<label for="quantity">
@Message
</label>
<input type="text" name="quantity" title="Edit Quantity" />
<input type="submit" value="Confirm" title="Confirm Change" />
</fieldset>
</form>
Am I doing something wrong here that could be causing this to cojombulate?
You should use
not form, you are sending this info through query string not as form element