UPDATE 语句的语法错误??? 找不到原因!!!
===============================================================
异常详细信息:
System.Data.OleDb.OleDbException: UPDATE 语句的语法错误。
源错误:
行 112: + "',Last_Time='" + txt_Last_Time + "',Note='" + txt_Note + "' WHERE id=" + editID.ToString();
行 113: jmgComm=new OleDbCommand(jmgUpdateData,jmgConn);
行 114: jmgComm.ExecuteNonQuery();
行 115:
行 116: Datagrid1.DataSource = jmgDS.Tables["Client"];
===============================================================
代码:
jmgConn.Open();
string txt_Name = ((TextBox)e.Item.FindControl("txt_Name")).Text;
string txt_Number = ((TextBox)e.Item.FindControl("txt_Number")).Text;
string txt_Company = ((TextBox)e.Item.FindControl("txt_Company")).Text;
string txt_Address = ((TextBox)e.Item.FindControl("txt_Address")).Text;
string txt_Phone = ((TextBox)e.Item.FindControl("txt_Phone")).Text;
string txt_Fax = ((TextBox)e.Item.FindControl("txt_Fax")).Text;
string txt_Handset = ((TextBox)e.Item.FindControl("txt_Handset")).Text;
string txt_EMail = ((TextBox)e.Item.FindControl("txt_EMail")).Text;
string txt_IM = ((TextBox)e.Item.FindControl("txt_IM")).Text;
string txt_IsBusiness = ((TextBox)e.Item.FindControl("txt_IsBusiness")).Text;
string txt_First_Time = ((TextBox)e.Item.FindControl("txt_First_Time")).Text;
string txt_Last_Time = ((TextBox)e.Item.FindControl("txt_Last_Time")).Text;
string txt_Note = ((TextBox)e.Item.FindControl("txt_Note")).Text;
jmgUpdateData = "update Client set Name='" + txt_Name + "',Number='" + txt_Number + "',Company='" + txt_Company + "',Address='" + txt_Address + "',Phone='" + txt_Phone + "',Fax='" + txt_Fax + "',Handset='" + txt_Handset + "',E-Mail='" + txt_EMail + "',IM='" + txt_IM + "',IsBusiness='" + txt_IsBusiness + "',First_Time='" + txt_First_Time + "',Last_Time='" + txt_Last_Time + "',Note='" + txt_Note + "' WHERE id=" + editID.ToString();
jmgComm=new OleDbCommand(jmgUpdateData,jmgConn);
jmgComm.ExecuteNonQuery();
Datagrid1.DataSource = jmgDS.Tables["Client"];
Datagrid1.DataBind();
jmgConn.Close();
showitem();
------解决方案--------------------除了ID,是不是其它全部是字符类型的?
如果不是,不要所有的字段都加上单引号
------解决方案--------------------ID是不是String.
试试这个
+ txt_Note + " ' WHERE id='" + editID.ToString() + "'";
------解决方案--------------------提示什么错误?
WHERE id=" + editID.ToString(); 在where前面加个空格试试;
------解决方案--------------------最好的办法,单步调试;把jmgUpdateData的代码拷贝到查询分析器里执行,再根据错误的提示查找问题;
------解决方案--------------------lz仔细点就好了。
------解决方案--------------------如果Id是数字:
....'" + txt_Note + " ' WHERE id=" + editID
----