zoukankan      html  css  js  c++  java
  • sql参数in

            /// <summary>
            /// 批量删除时的辅助方法
            /// </summary>
            /// <param name="sKeys">值列表</param>
            /// <param name="sbWhere">Sql in子句的参数</param>
            /// <returns>in子句的参数与值</returns>
            public List<SqlParameter> GetParaListByKeys(string sKeys, StringBuilder sbWhere)
            {
                string[] idList = sKeys.Split(',');
                List<SqlParameter> lstPara = new List<SqlParameter>(idList.Length);
                SqlParameter paraTemp = null;
                string sPara = "";
                for (int i = 0; i < idList.Length; i++)
                {
                    sPara = string.Format("@s{0}", i);
                    sbWhere.Append(sPara);
                    if (i != (idList.Length - 1))
                    {
                        sbWhere.Append(",");
                    }
                    paraTemp = new SqlParameter(sPara, idList[i].ToUpper());
                    lstPara.Add(paraTemp);
                }
                return lstPara;
            }
    
    
    
    使用:
                   StringBuilder _sqlStr = new StringBuilder();
                   _sqlStr.Append("select * from tablename where columnName in({0})");
                    StringBuilder sbWhere = new StringBuilder();
                    List<SqlParameter> lstPara = dba.GetParaListByKeys(arrPeiZhiXiangID, sbWhere);
                    string sSql = string.Format(_sqlStr.ToString(), sbWhere.ToString());
        
  • 相关阅读:
    uploadify上传文件代码
    事务处理拼接sql语句对数据库的操作.异常回滚
    Scrum【转】
    Redis
    mybatis
    Spring MVC
    IOC的理解(转载)
    spring IOC与AOP
    git
    python基础2
  • 原文地址:https://www.cnblogs.com/coder-soldier/p/7880367.html
Copyright © 2011-2022 走看看