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

ConvertToSqlByte() public static method

public static ConvertToSqlByte ( object value ) : SqlByte
value object
return System.Data.SqlTypes.SqlByte
        public static SqlByte ConvertToSqlByte(object value)
        {
            Debug.Assert(value != null, "null argument in ConvertToSqlByte");
            if ((value == DBNull.Value))
            { // null is not valid, SqlByte is struct
                return SqlByte.Null;
            }
            Type valueType = value.GetType();
            StorageType stype = DataStorage.GetStorageType(valueType);

            switch (stype)
            {
                case StorageType.SqlByte:
                    return (SqlByte)value;
                case StorageType.Byte:
                    return (byte)value;
                default:
                    throw ExceptionBuilder.ConvertFailed(valueType, typeof(SqlByte));
            }
        }

Usage Example

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