zoukankan      html  css  js  c++  java
  • 关于条件查询的参数condition的最佳方案

            当我们在DAL层写一个方法进行对数据的条件查询时:

                       public IList<UserInfo> GetUsersByCondition( stiring condition )

                          {

                               string   strSql=string.Format(" select * from UserInfo where {0}" ,conditon);

                               return GetUsreInfoBySql( strSql );

                          }

             时须在界面层对condition有二种处理:

              1.使用System.Text.StringBuilder处理,这种处理方式对于条件很多的情况有助于代码效率和内存使用。下面是查询按钮下的代码:

                  protected  void  btnSearch_Click( object sender,EventArgs e )

                   {

                      System.Text.StringBuilder  sb=new  System.Text.StringBuilder();

                      sb.Append("  1=1  ");

                      if ( ddlBranchThree.SelectedValue != "-1")

                         {

                            sb.AppendFormat("  and  Ctk_no={0}", ddlBranchThree.SelectedValue);

                         }

                      if ( ddlBranchTwo.SelectedValue != "-1")

                       {

                          sb.AppendFormat( "   and Cn_no={0}",ddlBranchTwo.SelectedValue);

                       }

                      if ( TxtTimeFirst.Value!=""&& TxtTimeEnd.Value!="")

                       {

                         sb.AppandFormat("  and Create_Time  between  '{0}'  and  '{1}'  ",TxtTimeFirst.Value+"0:00:00",TxtTimeEnd.Value+"23:59:59");

                       }

                      string   condition = sb.ToString();

                       Session["condition"] = condition  ;    //传向另一个页 面

                             ......

                   }

               第二种   以string 累加的方式,这里略!

  • 相关阅读:
    「酷客多」关注:马化腾公开演讲,透露2017年春节前会推出“小程序”
    微信小程序购物商城系统开发系列-目录结构
    微信小程序购物商城系统开发系列-工具篇
    上海闪酷成为京东商城第一批独立软件开发商(ISV)
    【FFMPEG】关于硬解码和软解码
    Git 别名配置
    【Linux】扩展阿里云数据盘分区和文件系统
    Python实现MQTT接收订阅数据
    【Linux】Devops的一些运维工具
    【Linux】YUM Repositories for CentOS, RHEL & Fedora Systems
  • 原文地址:https://www.cnblogs.com/yingger/p/2601316.html
Copyright © 2011-2022 走看看