下面错误是什么问题!
Server Error in '/school' Application.
--------------------------------------------------------------------------------You have an error in your SQL syntax near 'Set honor_name = 'dsb125' ,honor_date = '2005-04-26 00:00:00' ,honor_grade = '20' at line 1 
Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code. Exception Details: MySql.Data.MySqlClient.MySqlException: You have an error in your SQL syntax near 'Set honor_name = 'dsb125' ,honor_date = '2005-04-26 00:00:00' ,honor_grade = '20' at line 1Source Error: 
Line 192: con.Open();
Line 193:
Line 194: int ret = cmd.ExecuteNonQuery();
Line 195:
Line 196: con.Close();
 Source File: f:\Project\Projects\school\product\AddAchieve.aspx.cs    Line: 194 Stack Trace: 
[MySqlException: You have an error in your SQL syntax near 'Set honor_name = 'dsb125' ,honor_date = '2005-04-26 00:00:00' ,honor_grade = '20' at line 1]
   MySql.Data.MySqlClient.PacketReader.CheckForError() +91
   MySql.Data.MySqlClient.PacketReader.ReadHeader() +229
   MySql.Data.MySqlClient.PacketReader.OpenPacket() +119
   MySql.Data.MySqlClient.NativeDriver.ReadResult(UInt64& affectedRows, Int64& lastInsertId) +17
   MySql.Data.MySqlClient.CommandResult.ReadNextResult(Boolean isFirst) +71
   MySql.Data.MySqlClient.NativeDriver.SendQuery(Byte[] bytes, Int32 length, Boolean consume) +123
   MySql.Data.MySqlClient.MySqlCommand.GetNextResultSet(MySqlDataReader reader) +319
   MySql.Data.MySqlClient.MySqlCommand.Consume() +11
   MySql.Data.MySqlClient.MySqlCommand.ExecuteNonQuery() +98
   AddAchieve.btnSave_Click(Object sender, ImageClickEventArgs e) in f:\Project\Projects\school\product\AddAchieve.aspx.cs:194
   System.Web.UI.WebControls.ImageButton.OnClick(ImageClickEventArgs e) +105
   System.Web.UI.WebControls.ImageButton.RaisePostBackEvent(String eventArgument) +90
   System.Web.UI.WebControls.ImageButton.System.Web.UI.IPostBackEventHandler.RaisePostBackEvent(String eventArgument) +7
   System.Web.UI.Page.RaisePostBackEvent(IPostBackEventHandler sourceControl, String eventArgument) +11
   System.Web.UI.Page.RaisePostBackEvent(NameValueCollection postData) +33
   System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint) +5670 

解决方案 »

  1.   

    源代码如下:
    MySqlConnection con = new MySqlConnection(ConfigurationManager.AppSettings["connectString"]);
    MySqlCommand cmd;
    string strInsert = "Insert Ignore Into product_achieve Values Set ";
    string strUpdate = "Update product_achieve Set ";
    //公用字符串
    string strCommon = "honor_name = ?honor_name ";
    strCommon += ",honor_date = ?honor_date ";
    strCommon += ",honor_grade = ?honor_grade ";
    strCommon += ",honor_sort = ?honor_sort ";
    if (txtHonorUnit.Text != "")
    {
    strCommon += ",honor_unit = ?honor_unit ";
    }
    if (txtHonorSN.Text != "")
    {
    strCommon += ",honor_sn = ?honor_sn ";
    }//增加记录
    if (isAdd)
    {
    strInsert += strCommon;
    strInsert += ",product_id = ?product_id ";
    //获取学校的ID
    GlobalServer s = new GlobalServer();
    Person user = s.CurrentUser;
    string univ_id = user.CollegeID;
    strInsert += ",univ_id = ?univ_id"; cmd = new MySqlCommand(strInsert,con);
    cmd.Parameters.Add("?product_id",int.Parse(dropProductName.SelectedValue));
    cmd.Parameters.Add("?univ_id", univ_id);
    }
    else
    {
    //更新记录
    strUpdate += strCommon;
    strUpdate += "Where achieve_id = ?achieve_id";
    cmd = new MySqlCommand(strUpdate,con);
    cmd.Parameters.Add("?achieve_id",achieve_id);

    }
    //添加公有的变量
    cmd.Parameters.Add("?honor_name",txtHonorName.Text);
    cmd.Parameters.Add("?honor_date",DateTime.Parse(txtHonorDate.Text));
    cmd.Parameters.Add("?honor_grade",dropHonorGrade.SelectedValue);
    cmd.Parameters.Add("?honor_sort",dropHonorSort.SelectedValue);
    if(txtHonorUnit.Text != "")
    {
    cmd.Parameters.Add("?honor_unit",txtHonorUnit.Text);
    }if(txtHonorSN.Text != "")
    {
    cmd.Parameters.Add("?honor_sn",txtHonorSN.Text);
    }con.Open();int ret = cmd.ExecuteNonQuery();con.Close();if(ret > 0)
    {
    lblMessage.Text = "你已经成功操作" + ret.ToString() + "条记录!"; isAdd = true;
    achieve_id = -1;
    Response.Redirect("addachieve.aspx");
    }
      

  2.   

    try to run the sql in mysql, make sure the sql works firstyou might need to changecmd.Parameters.Add("?honor_grade",dropHonorGrade.SelectedValue);
    ==>
    cmd.Parameters.Add("?honor_grade",Convert.ToInt32(dropHonorGrade.SelectedValue));
      

  3.   

    Build the SQL text and execute it.
      

  4.   

    不要用Insert into table values set ... 这种语句
    用Insert table(...) values(...)