请教高手?

Genius125 2005-05-20 08:20:50
下面错误是什么问题!
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 1

Source 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


...全文
112 6 打赏 收藏 转发到动态 举报
写回复
用AI写文章
6 条回复
切换为时间正序
请发表友善的回复…
发表回复
saibing 2005-05-24
  • 打赏
  • 举报
回复
不要用Insert into table values set ... 这种语句
用Insert table(...) values(...)
kqh0319 2005-05-21
  • 打赏
  • 举报
回复
帮你顶
新鲜鱼排 2005-05-21
  • 打赏
  • 举报
回复
up
SeeSunSet 2005-05-21
  • 打赏
  • 举报
回复
Build the SQL text and execute it.
saucer 2005-05-21
  • 打赏
  • 举报
回复
try to run the sql in mysql, make sure the sql works first

you might need to change

cmd.Parameters.Add("?honor_grade",dropHonorGrade.SelectedValue);
==>
cmd.Parameters.Add("?honor_grade",Convert.ToInt32(dropHonorGrade.SelectedValue));
Genius125 2005-05-20
  • 打赏
  • 举报
回复
源代码如下:
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");
}

110,538

社区成员

发帖
与我相关
我的任务
社区描述
.NET技术 C#
社区管理员
  • C#
  • Web++
  • by_封爱
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告

让您成为最强悍的C#开发者

试试用AI创作助手写篇文章吧