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 累加的方式,这里略!

  • 相关阅读:
    Node.js 学习笔记(二)
    微服务网关 zuul 替代者 gateway 网关路由
    flowable 6.6.0 绕过自带的登录限制(免登录)
    `flowable.common.app.idmurl` must be set (flowable 6.6.0)
    gateway 跨域问题解决方案
    ueditor 在springboot 打jar运行时 找不到图片附件路径问题
    springboot 打jar 包部署时 读取外部配置文件
    Navicat连接MySQL Server8.0版本时出现Client does not support authentication protocol requested by server;解决如下
    flowable 通过模型model ID部署流程
    springboot 配置日志输出
  • 原文地址:https://www.cnblogs.com/yingger/p/2601316.html
Copyright © 2011-2022 走看看