无效的列名';a';.无效的列名';a';

本文关键字:无效 | 更新日期: 2023-09-27 17:59:04

我在catch中得到了这个错误。这是什么意思?我希望作业以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();
        }
    }

}

无效的列名';a';.无效的列名';a';

这是您的插入字符串"在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)"