我試圖插入信息到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();
}
你有所有列作爲varchar數據類型? – Sachin 2013-04-11 15:47:51
我會驗證你的每個字符串實際上是你期望的格式。 – Arran 2013-04-11 15:47:54
'[tblWorkshop]'? – I4V 2013-04-11 15:47:57