System.Data.Common.SqlConvert.ConvertToSqlDecimal C# (CSharp) Method

ConvertToSqlDecimal() public static method

public static ConvertToSqlDecimal ( object value ) : SqlDecimal
value object
return System.Data.SqlTypes.SqlDecimal
        public static SqlDecimal ConvertToSqlDecimal(object value)
        {
            Debug.Assert(value != null, "null argument in ConvertToSqlDecimal");
            if (value == DBNull.Value)
            {
                return SqlDecimal.Null;
            }
            Type valueType = value.GetType();
            StorageType stype = DataStorage.GetStorageType(valueType);

            switch (stype)
            {
                case StorageType.SqlDecimal:
                    return (SqlDecimal)value;
                case StorageType.Decimal:
                    return (decimal)value;
                case StorageType.SqlInt64:
                    return (SqlInt64)value;
                case StorageType.Int64:
                    return (long)value;
                case StorageType.UInt64:
                    return (ulong)value;
                case StorageType.SqlInt16:
                    return (SqlInt16)value;
                case StorageType.Int16:
                    return (short)value;
                case StorageType.UInt16:
                    return (ushort)value;
                case StorageType.SqlInt32:
                    return (SqlInt32)value;
                case StorageType.Int32:
                    return (int)value;
                case StorageType.UInt32:
                    return (uint)value;
                case StorageType.SqlByte:
                    return (SqlByte)value;
                case StorageType.Byte:
                    return (byte)value;
                case StorageType.SqlMoney:
                    return (SqlMoney)value;
                default:
                    throw ExceptionBuilder.ConvertFailed(valueType, typeof(SqlDecimal));
            }
        }

Usage Example

Esempio n. 1
0
 public override object ConvertValue(object value)
 {
     if (null != value)
     {
         return(SqlConvert.ConvertToSqlDecimal(value));
     }
     return(_nullValue);
 }
All Usage Examples Of System.Data.Common.SqlConvert::ConvertToSqlDecimal