• 根据转入的条件拼凑SQL条件语句


     /// <summary>
     /// SQL的条件符号枚举。dengyu表示“等于”,dayu表示“大于”,dayuOrdengyu表示“大于并且等于”,xiaoyuOrdengyu表示“小于并且等于”,inType表示“in”,like表示"like"
    /// </summary>
            enum OperaTeype { dengyu,dayu, xiaoyu, dayuOrdengyu, xiaoyuOrdengyu, inType, like };
    
     /// <summary>
            /// 根据转入的条件拼凑SQL条件语句
            /// </summary>
            /// <param name="type">条件符号。如大于,等于等</param>
            /// <param name="value">字段的值</param>
            /// <param name="filed">字段的名称</param>
            /// <param name="yihao">是否加引号</param>
            /// <returns></returns>
            private string GetReturnString(OperaTeype type, object value,string filed,bool yihao)
            {
                string strStart=" and ";
                if (value == null) 
                {
                    return string.Empty;
                }
                if (value.ToString().Length <= 0)
                {
                    return string.Empty;
                }
                if (yihao == true)
                {
                    value = "'" + value + "'";
                }
               
                if ((type == OperaTeype.dayu)) 
                {             
                        return string.Format("{0}{1}>{2}", strStart, filed, value);
                    
                }
                if ((type == OperaTeype.dengyu))
                {
                    return string.Format("{0}{1}={2}", strStart, filed, value);
                }
                if ((type == OperaTeype.xiaoyu))
                {
                    return string.Format("{0}{1}<{2}", strStart, filed, value);
                }
                if ((type == OperaTeype.dayuOrdengyu))
                {
                    return string.Format("{0}{1}>={2}", strStart, filed, value);
                }
                if ((type == OperaTeype.xiaoyuOrdengyu))
                {
                    return string.Format("{0}{1}<={2}", strStart, filed, value);
                }
                if ((type == OperaTeype.inType))
                {
                    return string.Format("{0}{1} in ({2})", strStart, filed, value);
                }
                if ((type == OperaTeype.like))
                {
                    return string.Format("{0}{1} like '%{2}%'", strStart, filed, value);
                }
                return string.Empty;
            }
    


       本人博客的文章大部分来自网络转载,因为时间的关系,没有写明转载出处和作者。所以在些郑重的说明:文章只限交流,版权归作者。谢谢

  • 相关阅读:
    POJ 3083 Children of the Candy Corn
    工程投诉过程中各建设主管理部门联系人表
    Csharp:ListView paging and groups from Any Data Sources
    Csharp: Listview convert Datatable and ListView.Group count
    Csharp:Windowsform using CheckedListBox Datasource
    jquery.jclock.js using different time zone offsets
    在请求和响应中使用 XML
    zindex属性简介
    谁是管理软件的优秀客户?
    知识管理项目简述
  • 原文地址:https://www.cnblogs.com/wzg0319/p/1777439.html
Copyright © 2020-2023  润新知