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 title=@title,contents=@content,dateTime=@dateTime,author=@author,categoryId=@categoryId, images=@images where newid=@newid";
采用参数化查询
你的sql语句是错误的
string strsql = "update NewsInfo set [title]=@title,[contents]=@contents,[dateTim]e=@dateTime,[author]=@author,[categoryId]=@categoryId,[images]=@images where [newid]=@newid";OleDbCommand cmd = new OleDbCommand(strsql, conn);conn.Open();cmd.Parameters.AddWithVaue("@title",title);cmd.Parameters.AddWithVaue("@contents",contents);其他类似.....int i = cmd.ExecuteNonQuery();