日期:2014-05-20  浏览次数:20993 次

“/”应用程序中的服务器错误。INSERT INTO 语句的语法错误。
public void Add(Sy.Model.Rczps model)
{
StringBuilder strSql=new StringBuilder();
  strSql.Append("insert into Rczps(");
  strSql.Append("Titles,Contens,Uworks,Number,Contact,AddTime)");
strSql.Append(" values (");
  strSql.Append("@Titles,@Contens,@Works,@Number,@Contact,@AddTime)");
OleDbParameter[] parameters = {
new OleDbParameter("@Titles", OleDbType.VarWChar,150),
new OleDbParameter("@Contens", OleDbType.VarWChar,150),
  new OleDbParameter("@Uworks", OleDbType.VarWChar,150),
  new OleDbParameter("@Number", OleDbType.Integer,4),
  new OleDbParameter("@Contact", OleDbType.VarWChar,150),
new OleDbParameter("@AddTime", OleDbType.Date)};
parameters[0].Value = model.Titles;
parameters[1].Value = model.Contens;
  parameters[2].Value = model.Uworks;
  parameters[3].Value = model.Number;
  parameters[4].Value = model.Contact;
  parameters[5].Value = model.AddTime;
   
  DbHelperOleDb.ExecuteSql(strSql.ToString(), parameters);
}


插入数据保存时“/”应用程序中的服务器错误。
--------------------------------------------

INSERT INTO 语句的语法错误。 
说明: 执行当前 Web 请求期间,出现未处理的异常。请检查堆栈跟踪信息,以了解有关该错误以及代码中导致错误的出处的详细信息。 

异常详细信息: System.Exception: INSERT INTO 语句的语法错误。

源错误: 


行 323: catch (System.Data.OleDb.OleDbException E)
行 324: {
行 325: throw new Exception(E.Message);
行 326: }
行 327: }
 

源文件: D:\项目\鄂尔多斯商会最新banben\ER\DBUtility\DbHelperOleDb.cs 行: 325 

堆栈跟踪: 


[Exception: INSERT INTO 语句的语法错误。]
  DBUtility.DbHelperOleDb.ExecuteSql(String SQLString, OleDbParameter[] cmdParms) in D:\项目\鄂尔多斯商会最新banben\ER\DBUtility\DbHelperOleDb.cs:325
  Sy.DAL.Rczps.Add(Rczps model) in D:\项目\鄂尔多斯商会最新banben\ER\Sy.DAL\Rczps.cs:70
  Sy.BLL.Rczps.Add(Rczps model) in D:\项目\鄂尔多斯商会最新banben\ER\Sy.BLL\Rczps.cs:38
  SyDemo.Admin.Rczps.Add.btnSave_Click(Object sender, EventArgs e) in D:\项目\鄂尔多斯商会最新banben\ER\SyDemo\Admin\Rczps\Add.aspx.cs:35
  System.Web.UI.WebControls.Button.OnClick(EventArgs e) +105
  System.Web.UI.WebControls.Button.RaisePostBackEvent(String eventArgument) +107
  System.Web.UI.WebControls.Button.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) +5087

 
各位高手大哥大姐们,帮帮忙

------解决方案--------------------
犯了一个严重错误,参数名不一致,请看红色部分

public void Add(Sy.Model.Rczps model)
{
StringBuilder strSql=new StringBuilder();
strSql.Append("insert into Rczps(");
strSql.Append("Titles,Contens,Uworks,Number,Contact,AddTime)");
strSql.Append(" values (");
strSql.Append("@Titles,@Contens,@Works,@Number,@Contact,@AddTime)");
OleDbParameter[] parameters = {
new OleDbParameter("@Titles", OleDbType.VarWChar,150),
new OleDbParameter("@Contens", OleDbType.VarWChar,150),
new OleDbParameter("@Uworks", OleDbType.VarWChar,150),
new OleDbParameter("@Number", OleDbType.Integer,4),