奇怪了...

今天做项目的时候,有一个修改的功能没实现,也没报错,查了半天,也不知道哪里出了问题,最后发现原来参数的顺序也很重要,奇怪了...,看看下面的代码

public void Update(Maticsoft.Model.Anli model)
  {
   StringBuilder strSql=new StringBuilder();
   strSql.Append("update CN_Anli set ");
   strSql.Append("title=@title,");
   strSql.Append("photo=@photo,");
   strSql.Append("links=@links,");
   strSql.Append("content=@content");
   strSql.Append(" where id=@id ");
            OleDbParameter[] parameters = {
     new OleDbParameter("@id", OleDbType.Integer,4),
     new OleDbParameter("@title", OleDbType.VarChar,200),
     new OleDbParameter("@photo", OleDbType.VarChar,200),
     new OleDbParameter("@links", OleDbType.VarChar,200),
     new OleDbParameter("@content", OleDbType.VarChar,0)};
   
   parameters[0].Value = model.id;
   parameters[1].Value = model.title;
   parameters[2].Value = model.photo;
   parameters[3].Value = model.links;
   parameters[4].Value = model.content;

   DbHelperOleDb.ExecuteSql(strSql.ToString(),parameters);
  }

这样写竟然不行,原因是id比较放在最后,即:

public void Update(Maticsoft.Model.Anli model)
  {
   StringBuilder strSql=new StringBuilder();
   strSql.Append("update CN_Anli set ");
   strSql.Append("title=@title,");
   strSql.Append("photo=@photo,");
   strSql.Append("links=@links,");
   strSql.Append("content=@content");
   strSql.Append(" where id=@id ");
            OleDbParameter[] parameters = {
     
     new OleDbParameter("@title", OleDbType.VarChar,200),
     new OleDbParameter("@photo", OleDbType.VarChar,200),
     new OleDbParameter("@links", OleDbType.VarChar,200),
     new OleDbParameter("@content", OleDbType.VarChar,0),
                    new OleDbParameter("@id", OleDbType.Integer,4)};
   parameters[0].Value = model.title;
   parameters[1].Value = model.photo;
   parameters[2].Value = model.links;
   parameters[3].Value = model.content;
            parameters[4].Value = model.id;

   DbHelperOleDb.ExecuteSql(strSql.ToString(),parameters);
  }

 郁闷...

 

posted @ 2011-03-04 14:58  双魂人生  阅读(245)  评论(0编辑  收藏  举报