我在catch中遇到此错误。这是什么意思 ?我希望在项目,文件夹名称“Class Content / Assignments”中将作业上传为pdf文件。我需要将此文件以及其他详细信息保存在数据库中,如下面的代码所示:
public partial class AddNotice : System.Web.UI.Page
{
string strcon = WebConfigurationManager.ConnectionStrings["StudentConnectionString1"].ConnectionString;
protected void Page_Load(object sender, EventArgs e)
{
// add session name
Label1.Text = Session["FacultyId"].ToString();
Label2.Text = DateTime.Now.ToString();
Button1.Click += Button1_Click;
}
protected void Button1_Click(object sender, EventArgs e)
{
if(FileUpload1.HasFile)
{
try
{
string filename = Path.GetFileName(FileUpload1.FileName);
FileUpload1.SaveAs(Server.MapPath("~/Class Content/Assignments") + filename);
Label3.Text = "Upload status: File uploaded!";
}
catch(Exception er)
{
Label3.Text = "Upload status: The file could not be uploaded. The following error occured: " + er.Message;
}
}
SqlConnection con = new SqlConnection(strcon);
SqlCommand cmd = new SqlCommand("Insert into NoticeBoard (FacultyId,Date,BranchId,SemesterId,Notice,Assignments) values (@fid,@d,@bid,@sid,@n,a)", con);
cmd.Parameters.AddWithValue("@fid", Label1.Text);
cmd.Parameters.AddWithValue("@d", Label2.Text);
cmd.Parameters.AddWithValue("@bid", TextBox1.Text);
cmd.Parameters.AddWithValue("@sid", TextBox2.Text);
cmd.Parameters.AddWithValue("@n", TextBox3.Text);
cmd.Parameters.AddWithValue("@a", FileUpload1.FileName);
try
{
con.Open();
cmd.ExecuteNonQuery();
Response.Write("Notice Generated");
}
catch(Exception er)
{
Response.Write(er.Message);
}
finally
{
con.Close();
}
}
}
答案 0 :(得分:0)
它是你的插入字符串 "插入NoticeBoard(FacultyId,Date,BranchId,SemesterId,Notice,Assignments)值(@ fid,@ d,@ bid,@ sid,@ n, a )"
"插入NoticeBoard(FacultyId,Date,BranchId,SemesterId,Notice,Assignments)值(@ fid,@ d,@ bid,@ sid,@ n, @a ) "