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

ConvertToSqlBinary() public static method

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

            switch (stype)
            {
                case StorageType.SqlBinary:
                    return (SqlBinary)value;
                case StorageType.ByteArray:
                    return (byte[])value;
                default:
                    throw ExceptionBuilder.ConvertFailed(valueType, typeof(SqlBinary));
            }
        }

Usage Example

 override public object ConvertValue(object value)
 {
     if (null != value)
     {
         return(SqlConvert.ConvertToSqlBinary(value));
     }
     return(NullValue);
 }
All Usage Examples Of System.Data.Common.SqlConvert::ConvertToSqlBinary