开发者

Updating just won't work

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
        </labe开发者_JS百科l>
        <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

if(Request.QueryString["IsBoxed"].AsBool() == true)

not form, you are sending this info through query string not as form element


Just a guess, but could it be that in your update queries you're updating integer types with strings? It seems that you're wrapping the values you're casting to integers in single quotes. I guess it all depends on how the types are defined in the database. If they're defined as integers try removing the single quotes. If they are defined as strings then there is not reason to cast them to integers. Just a guess.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜