Ejemplo n.º 1
0
        public TableColumn(DataRow row)
        {
            TableCatalog           = row["TABLE_CATALOG"].ToString();
            TableSchema            = row["TABLE_SCHEMA"].ToString();
            TableName              = row["TABLE_NAME"].ToString();
            ColumnName             = row["COLUMN_NAME"].ToString();
            ColumnDefault          = row["COLUMN_DEFAULT"].ToString();
            IsNullable             = row["IS_NULLABLE"].ToString();
            DataType               = row["DATA_TYPE"].ToString();
            CharacterSetCatalog    = row["CHARACTER_SET_CATALOG"].ToString();
            CharacterSetSchema     = row["CHARACTER_SET_SCHEMA"].ToString();
            CharacterSetName       = row["CHARACTER_SET_NAME"].ToString();
            CollationCatalog       = row["COLLATION_CATALOG"].ToString();
            OrdinalPosition        = ConvertUtility.ToInt32Nullable(row["ORDINAL_POSITION"]);
            CharacterMaximumLength = ConvertUtility.ToInt32Nullable(row["CHARACTER_MAXIMUM_LENGTH"]);
            CharacterOctetLength   = ConvertUtility.ToInt32Nullable(row["CHARACTER_OCTET_LENGTH"]);
            NumericScale           = ConvertUtility.ToInt32Nullable(row["NUMERIC_SCALE"]);
            NumericPrecisionRadix  = ConvertUtility.ToInt16Nullable(row["NUMERIC_PRECISION_RADIX"]);
            DatetimePrecision      = ConvertUtility.ToInt16Nullable(row["DATETIME_PRECISION"]);
            NumericPrecision       = ConvertUtility.ToByteNullable(row["NUMERIC_PRECISION"]);
            IsSparse               = ConvertUtility.ToBooleanNullable(row["IS_SPARSE"]);
            IsColumnSet            = ConvertUtility.ToBooleanNullable(row["IS_COLUMN_SET"]);
            IsFilestream           = ConvertUtility.ToBooleanNullable(row["IS_FILESTREAM"]);

            NetTypeName = DataTypeUtils.GetNetTypeName(DataType).Name;
        }
Ejemplo n.º 2
0
        private object TryConvert(object value, string toType, ref bool succes)
        {
            object retval = null;

            if (toType == typeof(Object).Name)
            {
                succes = true;
                return((object)value);
            }

            if (toType == typeof(Guid?).Name)
            {
                succes = true;
                return(ConvertUtility.ToGuidNullable(value));
            }

            if (toType == typeof(Guid).Name)
            {
                succes = true;
                return(ConvertUtility.ToGuid(value, Guid.Empty));
            }

            if (toType == typeof(Byte?).Name)
            {
                succes = true;
                return(ConvertUtility.ToByteNullable(value));
            }
            if (toType == typeof(Byte).Name)
            {
                succes = true;
                return(ConvertUtility.ToByte(value, 0));
            }
            if (toType == typeof(int?).Name)
            {
                succes = true;
                return(ConvertUtility.ToInt32Nullable(value));
            }
            if (toType == typeof(int).Name)
            {
                succes = true;
                return(ConvertUtility.ToInt32(value, 0));
            }
            if (toType == typeof(decimal?).Name)
            {
                succes = true;
                return(ConvertUtility.ToDecimalNullable(value));
            }
            if (toType == typeof(decimal).Name)
            {
                succes = true;
                return(ConvertUtility.ToDecimal(value, 0));
            }

            if (toType == typeof(Int16?).Name)
            {
                succes = true;
                return(ConvertUtility.ToInt16Nullable(value));
            }
            if (toType == typeof(Int16).Name)
            {
                succes = true;
                return(ConvertUtility.ToInt16(value, 0));
            }
            if (toType == typeof(Int32?).Name)
            {
                succes = true;
                return(ConvertUtility.ToInt32Nullable(value));
            }
            if (toType == typeof(Int32).Name)
            {
                succes = true;
                return(ConvertUtility.ToInt32(value, 0));
            }
            if (toType == typeof(Int64?).Name)
            {
                succes = true;
                return(ConvertUtility.ToInt64Nullable(value));
            }
            if (toType == typeof(Int64).Name)
            {
                succes = true;
                return(ConvertUtility.ToInt64(value, 0));
            }
            if (toType == typeof(float?).Name)
            {
                succes = true;
                return(ConvertUtility.ToSingleNullable(value));
            }
            if (toType == typeof(float).Name)
            {
                succes = true;
                return(ConvertUtility.ToSingle(value, 0));
            }
            if (toType == typeof(Single?).Name)
            {
                succes = true;
                return(ConvertUtility.ToSingleNullable(value));
            }
            if (toType == typeof(Single).Name)
            {
                succes = true;
                return(ConvertUtility.ToSingle(value, 0));
            }
            if (toType == typeof(double?).Name)
            {
                succes = true;
                return(ConvertUtility.ToDoubleNullable(value));
            }
            if (toType == typeof(double).Name)
            {
                succes = true;
                return(ConvertUtility.ToDouble(value, 0));
            }
            if (toType == typeof(Double?).Name)
            {
                succes = true;
                return(ConvertUtility.ToDoubleNullable(value));
            }
            if (toType == typeof(Double).Name)
            {
                succes = true;
                return(ConvertUtility.ToDouble(value, 0));
            }

            if (toType == typeof(bool?).Name)
            {
                succes = true;
                return(ConvertUtility.ToBooleanNullable(value));
            }
            if (toType == typeof(bool).Name)
            {
                succes = true;
                return(ConvertUtility.ToBoolean(value, false));
            }

            if (toType == typeof(DateTime).Name)
            {
                DateTime DateTimeValue = DateTime.Now;
                succes = DateTime.TryParse(ConvertUtility.HandleNull(value, string.Empty).ToString(), out DateTimeValue);
                retval = DateTimeValue;
            }
            if (toType == typeof(DateTime?).Name)
            {
                DateTime DateTimeValue = DateTime.Now;
                succes = DateTime.TryParse(ConvertUtility.HandleNull(value, string.Empty).ToString(), out DateTimeValue);
                if (!succes)
                {
                    retval = null;
                }
                retval = DateTimeValue;
            }

            return(retval);
        }