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

ConvertToSqlInt16() public static method

public static ConvertToSqlInt16 ( object value ) : SqlInt16
value object
return System.Data.SqlTypes.SqlInt16
        public static SqlInt16 ConvertToSqlInt16(object value)
        {
            Debug.Assert(value != null, "null argument in ConvertToSqlInt16");
            if (value == DBNull.Value)
            {
                return SqlInt16.Null;
            }
            Type valueType = value.GetType();
            StorageType stype = DataStorage.GetStorageType(valueType);
            switch (stype)
            {
                case StorageType.Byte:
                    return (byte)value;
                case StorageType.Int16:
                    return (short)value;
                case StorageType.SqlByte:
                    return (SqlByte)value;
                case StorageType.SqlInt16:
                    return (SqlInt16)value;
                default:
                    throw ExceptionBuilder.ConvertFailed(valueType, typeof(SqlInt16));
            }
        }

Usage Example

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