Exemplo n.º 1
0
        /// <summary>
        /// 创建不等于条件表达式
        /// </summary>
        /// <param name="fieldname">左边字段名称</param>
        /// <param name="parametname">右边参数名称</param>
        /// <param name="parametvalue">右边参数值</param>
        /// <param name="paramet">返回与条件表达式一起使用的参数表达式</param>
        /// <returns></returns>
        internal static string CreateNotEqWhere(
            string fieldname,
            string parametname,
            object parametvalue,
            out IDataParamet paramet)
        {
            paramet = null;
            if (string.IsNullOrEmpty(fieldname) || string.IsNullOrEmpty(parametname))
            {
                return(null);
            }
            string left = fieldname;

            if (MsSqlServerHelper.IsValidFieldName(fieldname))
            {
                left = MsSqlServerHelper.GetFeildNameInSqlExpress(fieldname);
            }
            if (parametvalue == null)
            {
                return(string.Format("{0} IS NOT NULL", left));
            }
            string right = MsSqlServerHelper.GetParametName(parametname);

            paramet = new DataParamet()
            {
                Direction = System.Data.ParameterDirection.Input, Name = parametname, Value = parametvalue, ValueType = parametvalue.GetType()
            };
            return(string.Format("{0}<>{1}", left, right));
        }
Exemplo n.º 2
0
        /// <summary>
        /// 创建以parametvalue开始或在parametvalue中以列的值开始的条件表达式
        /// </summary>
        /// <param name="fieldname">列字段名称</param>
        /// <param name="parametname">参数名称</param>
        /// <param name="parametvalue">参数值</param>
        /// <param name="parametIsExpress">是否是取在parametvalue中以列的值开始的条件表达式</param>
        /// <param name="paramet"></param>
        /// <returns></returns>
        internal static string CreateFirstIndexOfWhere(
            string fieldname,
            string parametname,
            string parametvalue,
            bool parametIsExpress,
            out IDataParamet paramet)
        {
            paramet = null;
            if (string.IsNullOrEmpty(fieldname) || string.IsNullOrEmpty(parametname))
            {
                return(null);
            }
            string left = fieldname;

            if (MsSqlServerHelper.IsValidFieldName(fieldname))
            {
                left = MsSqlServerHelper.GetFeildNameInSqlExpress(fieldname);
            }
            if (parametvalue == null)
            {
                return(null);
            }
            string right = MsSqlServerHelper.GetParametName(parametname);

            paramet = new DataParamet()
            {
                Direction = System.Data.ParameterDirection.Input, Name = parametname, Value = parametvalue, ValueType = parametvalue.GetType()
            };
            if (parametIsExpress)
            {
                return(string.Format("CHARINDEX({1},{0})=1", left, right));
            }
            else
            {
                return(string.Format("CHARINDEX({0},{1})=1", left, right));
            }
        }