/// <summary>
 /// 创建不等于条件表达式(左边和右边名称一样)
 /// </summary>
 /// <param name="fieldname">字段名称</param>
 /// <param name="parametvalue">参数值</param>
 /// <param name="paramet">返回与条件表达式一起使用的参数表达式</param>
 /// <returns></returns>
 internal static string CreateNotEqWhere(
     string fieldname,
     object parametvalue,
     out IDataParamet paramet)
 {
     return(CreateNotEqWhere(fieldname, fieldname, parametvalue, out paramet));
 }
        /// <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));
        }
Beispiel #3
0
 /// <summary>
 /// 设置命令参数
 /// </summary>
 /// <param name="dbp"></param>
 /// <param name="p"></param>
 protected virtual void SetDbDataParameter(IDbDataParameter dbp, IDataParamet p)
 {
     dbp.Direction = p.Direction;
     dbp.DbType    = p.ValueType.GetDbType();
     switch (dbp.DbType)
     {
     case DbType.String:
     case DbType.Object:
     case DbType.AnsiString:
     case DbType.AnsiStringFixedLength:
     case DbType.StringFixedLength:
     {
         if (p.ValueSize > 0)
         {
             dbp.Size = p.ValueSize;
         }
         break;
     }
     }
     if (p.Value != null)
     {
         dbp.Value = p.Value;
     }
     else
     {
         dbp.Value = DBNull.Value;
     }
     dbp.ParameterName = CreateParametName(p.Name);
 }
 protected override void SetDbDataParameter(System.Data.IDbDataParameter dbp, IDataParamet p)
 {
     base.SetDbDataParameter(dbp, p);
     if (dbp is SqlParameter && dbp.DbType == System.Data.DbType.Object)
     {
         ((SqlParameter)dbp).SqlDbType = System.Data.SqlDbType.NText;
     }
 }
 /// <summary>
 /// 创建以parametvalue开始或在parametvalue中以列的值开始的条件表达式
 /// </summary>
 /// <param name="fieldname">列字段名称</param>
 /// <param name="parametvalue">参数值</param>
 /// <param name="parametIsExpress">是否是取在parametvalue中以列的值开始的条件表达式</param>
 /// <param name="paramet"></param>
 /// <returns></returns>
 internal static string CreateFirstIndexOfWhere(
     string fieldname,
     string parametvalue,
     bool parametIsExpress,
     out IDataParamet paramet)
 {
     return(CreateFirstIndexOfWhere(fieldname, fieldname, parametvalue, parametIsExpress, out paramet));
 }
 /// <summary>
 /// 创建不等于条件表达式(左边和右边名称一样)
 /// </summary>
 /// <param name="dbtypename">数据库类型</param>
 /// <param name="fieldname">字段名称</param>
 /// <param name="parametvalue">参数值</param>
 /// <param name="paramet">返回与条件表达式一起使用的参数表达式</param>
 /// <returns></returns>
 public static string CreateNotEqWhere(
     string dbtypename,
     string fieldname,
     object parametvalue,
     out IDataParamet paramet)
 {
     if (IsMsSqlDb(dbtypename))
     {
         return(MSSql_QuerySqlFactory.CreateNotEqWhere(fieldname, parametvalue, out paramet));
     }
     throw new NotSupportException(ErrorCodes.NotSupportDbType, string.Format(LocalResource.NotSupportDbType, dbtypename));
 }
Beispiel #7
0
 /// <summary>
 /// 获取指定字段名称的参数值
 /// </summary>
 /// <param name="fieldname">字段名称</param>
 /// <param name="hz">参数后缀</param>
 /// <returns>参数值</returns>
 internal static object GetParametValue(string fieldname, string hz, IEnumerable <IDataParamet> p)
 {
     if (p != null)
     {
         string       name = GenerateParametName(fieldname, hz);
         IDataParamet xx   = p.FirstOrDefault(f => string.Equals(f.Name, name, StringComparison.OrdinalIgnoreCase));
         if (xx != null)
         {
             return(xx.Value);
         }
     }
     return(null);
 }
        /// <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));
            }
        }