添加到网站重制的数据库时出错

时间:2015-01-21 17:07:44

标签: sql asp.net oop

我正在尝试通过我制作的课程将一个项目添加到我的数据库中。我有这个错误 mscorlib.dll中出现“System.FormatException”类型的异常,但未在用户代码中处理

其他信息:输入字符串的格式不正确。

我不知道哪里出错了,但这是我的代码

       protected void btnAdd_Click(object sender, EventArgs e)
    {
        string filename = FileUpload1.PostedFile.FileName;
        int filebytes = FileUpload1.PostedFile.ContentLength;
        byte[] image = new byte[filebytes];
        FileUpload1.PostedFile.InputStream.Read(image, 0, filebytes);

        string imagepath = "~/Image/" + filename;

        pro.SaveNewProduct(int.Parse(txtID.Text), txtPName.Text, int.Parse(txtPrice.Text), txtDes.Text, imagepath, int.Parse(DDLCatagory.SelectedValue), int.Parse(DDLNPCAA.SelectedValue), DDLproductype.SelectedValue, int.Parse(txtQuant.Text));
    }


        public void SaveNewProduct(int id, string name, int price, string description, string image, int catagory, int popularity, string kindof, int quantity)
    {
        dal.ClearParams();
        dal.AddParam("@ItemID", id);
        dal.AddParam("@Name", name);
        dal.AddParam("@Price", price);
        dal.AddParam("@Descriptions", description);
        dal.AddParam("@Images", image);
        dal.AddParam("@Catagory", catagory);
        dal.AddParam("@Popularity", popularity);
        dal.AddParam("@Type", kindof);
        dal.AddParam("@Quantity", quantity);
        dal.ExecuteProcedure("spSNI");

    }    

我也在pro.savenewproduct上收到错误。 我已经三次检查,看看我输入的参数是否有任何错误,到目前为止似乎没有任何错误。

我假设你的意思是这个,我也只在文本框中键入20以获得此错误:

<asp:Content ID="Content2" ContentPlaceHolderID="ContentPlaceHolder1" runat="server">
<div style="float:right; margin-right:300px">
<asp:Image ID="Image1" runat="server" Width="200px" Height="200px" />
<br />
<asp:FileUpload ID="FileUpload1" runat="server" />
<br /><br />
<asp:Label ID="lblPName" runat="server" Text="Product Name"></asp:Label>
<asp:TextBox runat="server" ID="txtPName"></asp:TextBox>
<asp:Label ID="lblPrice" runat="server" Text="Price"></asp:Label>
<asp:TextBox runat="server" ID="txtPrice"></asp:TextBox>
<br /><br />
<asp:Label ID="lblDes" runat="server" Text="Description"></asp:Label>
<asp:TextBox runat="server" ID="txtDes"></asp:TextBox>
<asp:Label ID="lblquant" runat="server" Text="Quantity"></asp:Label>
<asp:TextBox runat="server" ID="txtQuant"></asp:TextBox>
<br /><br />
<asp:DropDownList runat="server" ID="DDLproductype">
    <asp:ListItem>Select Product Type</asp:ListItem>
    <asp:ListItem>Physical Product</asp:ListItem>
    <asp:ListItem>Service Product</asp:ListItem>
</asp:DropDownList>
<asp:DropDownList runat="server" ID="DDLNPCAA"></asp:DropDownList>
<asp:DropDownList runat="server" ID="DDLCatagory"></asp:DropDownList>
<br />
<asp:Label ID="lblID" runat="server" Text="ID of Existing Item"></asp:Label>
<asp:TextBox ID="txtID" runat="server"></asp:TextBox>
<asp:DropDownList ID="DDListofitems" runat="server"></asp:DropDownList>
<br />
<asp:Button ID="btnupdateID" runat="server" Text="Update ID of Item" OnClientClick="btnupdateID_Click" OnClick="btnupdateID_Click" />
<br /><br />
<asp:Button ID="btnAdd" runat="server" Text="Add New Item Or Update" OnClick="btnAdd_Click" />

        

0 个答案:

没有答案