System.Data.Linq.dll中出现“System.Data.SqlClient.SqlException”类型的异常,但未在用户代码中处理

时间:2016-03-07 16:29:41

标签: database submitchanges

protected void btnInsert_Click(object sender, EventArgs e)
    {
        if (Page.IsValid)
        {
            string Name = txtBookName.Text;
            string Author = txtAuthor.Text;
            string Publisher = txtPublisher.Text;
            string Price = txtPrice.Text;

            //save photo
            string path = MapPath("~/Photos/");
            string filename = Guid.NewGuid().ToString("N") + ".jpg";

            SimpleImage img = new SimpleImage(fupPhoto.FileContent);
            img.Square();
            img.Resize(150);
            img.SaveAs(path + filename);

            Book b = new Book
            {
                name = Name,
                author = Author,
                publisher = Publisher,
                price = Price,
                photo = filename
            };

            db.Books.InsertOnSubmit(b);
            db.SubmitChanges();

            Response.Redirect("List.aspx");
        }
    }

0 个答案:

没有答案