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

ConvertToSqlInt32() public static method

public static ConvertToSqlInt32 ( object value ) : SqlInt32
value object
return System.Data.SqlTypes.SqlInt32
        public static SqlInt32 ConvertToSqlInt32(object value)
        {
            Debug.Assert(value != null, "null argument in ConvertToSqlInt32");
            if (value == DBNull.Value)
            {
                return SqlInt32.Null;
            }
            Type valueType = value.GetType();
            StorageType stype = DataStorage.GetStorageType(valueType);
            switch (stype)
            {
                case StorageType.SqlInt32:
                    return (SqlInt32)value;
                case StorageType.Int32:
                    return (int)value;
                case StorageType.SqlInt16:
                    return (SqlInt16)value;
                case StorageType.Int16:
                    return (short)value;
                case StorageType.UInt16:
                    return (ushort)value;
                case StorageType.SqlByte:
                    return (SqlByte)value;
                case StorageType.Byte:
                    return (byte)value;

                default:
                    throw ExceptionBuilder.ConvertFailed(valueType, typeof(SqlInt32));
            }
        }

Usage Example

示例#1
0
 public override object ConvertValue(object?value)
 {
     if (null != value)
     {
         return(SqlConvert.ConvertToSqlInt32(value));
     }
     return(_nullValue);
 }
All Usage Examples Of System.Data.Common.SqlConvert::ConvertToSqlInt32