我正在尝试将信息插入到sql express 2008数据库的表中,当我尝试插入字段时,我收到错误“'附近的语法不正确',”有人可以向我解释我的代码中有什么导致这个问题?
protected void insertworkshop_Click(object sender, EventArgs e)
{
using (SqlConnection conn2 = new SqlConnection(@"Data Source=CIS489_3\WILDLIFE;Initial Catalog=WildLife_Education;Integrated Security=True;"))
{
SqlCommand CmdSql2 = new SqlCommand("INSERT INTO [tblWorkshop] ([WorkshopName], [WorkshopBeginingDate], [WorkshopEndingDate], [WorkshopLocation], [InstructorID])VALUES (@WorkshopName, @WorkshopBeginingDate, @WorkshopEndingDate, @WorkshopLocation, @InstructorID)", conn2);
conn2.Open();
CmdSql2.Parameters.AddWithValue("@WorkshopName", workshopinsertname.Text.ToString());
CmdSql2.Parameters.AddWithValue("@WorkshopBeginingDate", workshopinsertstart.Text.ToString());
CmdSql2.Parameters.AddWithValue("@[WorkshopEndingDate", workshopinsertend.Text.ToString());
CmdSql2.Parameters.AddWithValue("@WorkshopLocation", workshopinsertlocation.Text.ToString());
CmdSql2.Parameters.AddWithValue("@InstructorID", insertinstructorid.SelectedValue.ToString());
CmdSql2.Connection = conn2;
CmdSql2.ExecuteNonQuery();
conn2.Close();
UpdateInsertWorkshop.Update();
this.addnewworkshop_ModalPopupExtender.Hide();
}
答案 0 :(得分:9)
在您的代码中,以下行还有一个额外的[
:
CmdSql2.Parameters.AddWithValue("@[WorkshopEndingDate", workshopinsertend.Text.ToString());
应该是:
CmdSql2.Parameters.AddWithValue("@WorkshopEndingDate", workshopinsertend.Text.ToString());
答案 1 :(得分:0)
这是因为附近有问题。正如上面的答案所说,你的错误是不需要的[。
只是一个恼人的错字。