【发布时间】:2014-02-25 19:17:02
【问题描述】:
单击时,我正在使用一个按钮将产品添加到数据库中。这是我编写的代码,但它创建了一个未处理的异常。请帮我改正...
protected void Button1_Click(object sender, EventArgs e)
{
string s = @"~\Images" + FileUpload1.FileName;
FileUpload1.PostedFile.SaveAs(Server.MapPath(s));
string ConStr = ConfigurationManager.ConnectionStrings["HoriZon"].ConnectionString;
SqlConnection NewCon = new SqlConnection(ConStr);
NewCon.Open();
String cmd1 = "INSERT INTO Subjects(SubjectName, Description, ImagePath, UnitPrice, CategoryID) values('" + name.Text + "','" + description.Text + "','" + s + "', '" + price.Text + "', '" + "SELECT CategoryID FROM dbo.Categories WHERE CategoryName = '" + catText.Text + "'" +"')";
SqlCommand b = new SqlCommand(cmd1, NewCon);
b.ExecuteNonQuery();
NewCon.Close();
}
【问题讨论】:
-
你看到了什么异常?
标签: sql-server sql-server-2008 c#-4.0