Пример #1
0
        /// <summary>
        /// 创建命令参数
        /// </summary>
        /// <param name="providerFactory">创建数据源类的提供程序</param>
        /// <param name="name">参数名称</param>
        /// <param name="value">参数值</param>
        /// <param name="dbType">数据类型</param>
        /// <param name="size">参数大小</param>
        /// <param name="precision">精度</param>
        /// <param name="scale">小数位</param>
        /// <param name="direction">方向</param>
        /// <returns></returns>
        public static IDbDataParameter CreateParameter(this DbProviderFactory providerFactory, string name, object value,
                                                       DbType?dbType = null, int?size = null, int?precision = null, int?scale = null, ParameterDirection?direction = null)
        {
            IDbDataParameter parameter = providerFactory.CreateParameter();

            parameter.ParameterName = name;
            parameter.Value         = value;
            DataExtensions.FixParameter(parameter, value, dbType, size, precision, scale, direction);

            // 返回创建的参数
            return(parameter);
        }
Пример #2
0
        /// <summary>
        /// 创建参数对象的新实例,并添加到 IDbCommand.Parameters 集合
        /// </summary>
        /// <param name="cmd">SQL 命令</param>
        /// <param name="name">参数名称</param>
        /// <param name="value">参数值</param>
        /// <param name="dbType">数据类型</param>
        /// <param name="size">参数大小</param>
        /// <param name="precision">精度</param>
        /// <param name="scale">小数位</param>
        /// <param name="direction">方向</param>
        public static IDbDataParameter CreateParameter(this IDbCommand cmd, string name, object value,
                                                       DbType?dbType = null, int?size = null, int?precision = null, int?scale = null, ParameterDirection?direction = null)
        {
            IDbDataParameter parameter = cmd.CreateParameter();

            parameter.ParameterName = name;
            parameter.Value         = value;
            DataExtensions.FixParameter(parameter, value, dbType, size, precision, scale, direction);
            cmd.Parameters.Add(parameter);

            // 返回创建的参数
            return(parameter);
        }