Пример #1
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="table"></param>
        /// <param name="parameters"></param>
        public virtual void SetParameters(SqlTable table, StatementParameterCollection parameters)
        {
            if (HasQuery)
            {
                query.SetParameters(table, parameters);
            }
            else
            {
                IColumn sqlColumn = table.ColumnList.FirstOrDefault(item => item.Name.Equals(column, StringComparison.OrdinalIgnoreCase));
                DbType? dataType  = sqlColumn != null ? sqlColumn.ColumnType : null;

                StatementParameter parameter1 = new StatementParameter {
                    Name = index.ToString()
                };
                SqlUtils.PrepareParameter(parameter1, val, dataType);
                parameters.Add(parameter1);

                if (op.ToUpper().IndexOf(Between, StringComparison.Ordinal) > -1)
                {
                    StatementParameter parameter2 = new StatementParameter {
                        Name = index2.ToString()
                    };
                    SqlUtils.PrepareParameter(parameter2, val2, dataType);
                    parameters.Add(parameter2);
                }
            }
        }
Пример #2
0
 public virtual void SetInParameters(SqlTable table, StatementParameterCollection parameters)
 {
     if (HasQuery)
     {
         query.SetParameters(table, parameters);
     }
     else
     {
         var values = (IList)Value;
         if (values != null && values.Count > 0)
         {
             IColumn sqlColumn = table.ColumnList.FirstOrDefault(item => item.Name.Equals(column, StringComparison.OrdinalIgnoreCase));
             DbType? dataType  = sqlColumn != null ? sqlColumn.ColumnType : null;
             for (Int32 i = 0; i < values.Count; i++)
             {
                 StatementParameter parameter = new StatementParameter {
                     Name = index.ToString()
                 };
                 SqlUtils.PrepareParameter(parameter, values[i], dataType);
                 parameters.Add(parameter);
                 index++;
             }
         }
     }
 }
Пример #3
0
 public static void PrepareParameter(StatementParameter parameter, Object value)
 {
     if (value == null || value == DBNull.Value)
     {
         PrepareParameterType(parameter, null);
         parameter.Value = DBNull.Value;
     }
     else
     {
         var dbType = value.GetType();
         PrepareParameterType(parameter, dbType);
         parameter.Value = value;
     }
 }
Пример #4
0
        private StatementParameterCollection ChangeStateParm(DbCommand dbCmd)
        {
            DbParameterCollection        parmsList = dbCmd.Parameters;
            StatementParameterCollection sparmList = new StatementParameterCollection();

            foreach (DbParameter dbParm in parmsList)
            {
                StatementParameter stateParm = new StatementParameter();
                stateParm.Name      = dbParm.ParameterName;
                stateParm.DbType    = dbParm.DbType;
                stateParm.Direction = dbParm.Direction;

                stateParm.Size  = dbParm.Size;
                stateParm.Value = dbParm.Value;
                sparmList.Add(stateParm);
                // ParmsList.Add(stateParm);
            }
            return(sparmList);
        }
Пример #5
0
        public static void PrepareParameter(StatementParameter parameter, Object value, DbType?dataType)
        {
            if (!dataType.HasValue)
            {
                PrepareParameter(parameter, value);
            }
            else
            {
                parameter.DbType = dataType.Value;

                if (value == null || value == DBNull.Value)
                {
                    parameter.Value = DBNull.Value;
                }
                else
                {
                    parameter.Value = value;
                }
            }
        }
Пример #6
0
        private StatementParameterCollection ChangeStateParm(DbCommand dbCmd)
        {
            DbParameterCollection parmsList = dbCmd.Parameters;
            StatementParameterCollection sparmList = new StatementParameterCollection();
            foreach (DbParameter dbParm in parmsList)
            {
                StatementParameter stateParm = new StatementParameter();
                stateParm.Name = dbParm.ParameterName;
                stateParm.DbType = dbParm.DbType;
                stateParm.Direction = dbParm.Direction;

                stateParm.Size = dbParm.Size;
                stateParm.Value = dbParm.Value;
                sparmList.Add(stateParm);
                // ParmsList.Add(stateParm);
            }
            return sparmList;
        }
Пример #7
0
 public static void PrepareParameterType(StatementParameter parameter, Type type)
 {
     parameter.DbType = ResolveType(type);
 }