C# 无效的列名';a';。无效的列名';a';
我在接球时犯了这个错误。这是什么意思?我想把作业作为pdf文件上传到项目中,文件夹名为“课堂内容/作业”。我需要将此文件以及其他详细信息保存在数据库中,如下面的代码所示:C# 无效的列名';a';。无效的列名';a';,c#,asp.net,file-upload,C#,Asp.net,File Upload,我在接球时犯了这个错误。这是什么意思?我想把作业作为pdf文件上传到项目中,文件夹名为“课堂内容/作业”。我需要将此文件以及其他详细信息保存在数据库中,如下面的代码所示: public partial class AddNotice : System.Web.UI.Page { string strcon = WebConfigurationManager.ConnectionStrings["StudentConnectionString1"].ConnectionString; prot
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();
}
}
}
这是你的插入字符串
“将值(@fid、@d、@bid、@sid、@n、a)插入布告栏(传真ID、日期、BranchId、传真ID、通知、作业)。”
“将值(@fid、@d、@bid、@sid、@n、@a)插入布告栏(FacultyId、Date、BranchId、SemesterId、NOTIONE、ASSIGNS)。”您在Insert命令中忘记了@sign。