zoukankan      html  css  js  c++  java
  • 奇怪了...

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

    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);
      }

     郁闷...

    多思考,多创新,才是正道!
  • 相关阅读:
    锁优化
    无同步方案
    线程安全
    vue 监听路由变化
    ES6-解构赋值
    微信小程序中遮罩层的滚动穿透问题
    JavaScirpt对象原生方法
    JavaScript-window
    JavaScript字符串API
    JavaScript常用数组操作方法,包含ES6方法
  • 原文地址:https://www.cnblogs.com/shuang121/p/1970927.html
Copyright © 2011-2022 走看看