当前位置: 代码迷 >> .NET Framework >> access解决思路
  详细解决方案

access解决思路

热度:105   发布时间:2016-05-02 00:31:38.0
access
在access数据库中出现以下问题
异常详细信息: System.Data.OleDb.OleDbException: 无效的 SQL语句;期待 'DELETE'、'INSERT'、'PROCEDURE'、'SELECT'、或 'UPDATE'。

源错误: 
行 27: OleDbCommand cmd = new OleDbCommand(strsql, conn);
行 28: conn.Open();
行 29: int i = cmd.ExecuteNonQuery();
行 30: conn.Close();
行 31: return i;
 
语句是string strsql = "update NewsInfo set title='" + title + "',contents='" + contents + "',dateTime='" + dateTime + "',author='" + author + "',categoryId='" + categoryId + "', images'" + images + "' where newid='"+newid +"'";
newid不是自己增长的,是数字类型的


------解决方案--------------------
string strsql = "update NewsInfo set [email protected],[email protected],[email protected],[email protected],[email protected], [email protected] where [email protected]";
采用参数化查询

你的sql语句是错误的

C# code
string strsql = "update NewsInfo set [title][email protected],[contents][email protected],[dateTim][email protected],[author][email protected],[categoryId][email protected],[images][email protected] where [newid][email protected]";OleDbCommand cmd = new OleDbCommand(strsql, conn);conn.Open();cmd.Parameters.AddWithVaue("@title",title);cmd.Parameters.AddWithVaue("@contents",contents);其他类似.....int i = cmd.ExecuteNonQuery();
  相关解决方案