mscorlib.dll中出现“System.FormatException”类型的异常,但未在用户代码中处理

时间:2016-02-20 13:27:43

标签: c#

protected void btnAdd_Click(object sender, EventArgs e)
    {
        if (!string.IsNullOrWhiteSpace(Request.QueryString["id"]))
        {
            string kundeID = Context.User.Identity.GetUserId();
            if (kundeID != null)
            {

                int id = Convert.ToInt32(Request.QueryString["id"]);
                int totalsum = Convert.ToInt32(ddlAmount.SelectedValue);



                Handlevogn handlevogn = new Handlevogn
                {
                    TotalSum = totalsum,
                    KundeID = short.Parse(kundeID),
                    Dato = DateTime.Now,
                    ErIHandlevogn = true,
                    ProduktID = id
                };

                HandlevognModell model = new HandlevognModell();
                lblResult.Text = model.InsertHandlevogn(handlevogn);
            }
            else
            {
                lblResult.Text = "Please log in to order items";
            }
  

mscorlib.dll中发生了'System.FormatException'类型的异常   但未在用户代码中处理

Here is the error i get when I try to add items to my shoppingcart in my database

Model.cs file

1 个答案:

答案 0 :(得分:0)

尝试添加toString调用

KundeID = short.Parse(kundeID.ToString());

所以它基本上就像

Handlevogn handlevogn = new Handlevogn
            {
                TotalSum = totalsum,
                KundeID = short.Parse(kundeID.toString()),
                Dato = DateTime.Now,
                ErIHandlevogn = true,
                ProduktID = id
            };

希望这会对你有所帮助。