GetComValueFromSqlVariant() статический приватный Метод

static private GetComValueFromSqlVariant ( object sqlVal ) : object
sqlVal object
Результат object
 private object ValidateBulkCopyVariant(object value)
 {
     switch (MetaType.GetMetaTypeFromValue(value).TDSType)
     {
     case 0xa5:
     case 0xa7:
     case 0xe7:
     case 0x7f:
     case 0x24:
     case 40:
     case 0x29:
     case 0x2a:
     case 0x2b:
     case 0x30:
     case 50:
     case 0x34:
     case 0x38:
     case 0x3b:
     case 60:
     case 0x3d:
     case 0x3e:
     case 0x6c:
         if (value is INullable)
         {
             return(MetaType.GetComValueFromSqlVariant(value));
         }
         return(value);
     }
     throw SQL.BulkLoadInvalidVariantValue();
 }
Пример #2
0
        internal static object GetComValue(SqlDbType type, object sqlVal)
        {
            object comVal = DBNull.Value;

            // check nullable (remember the sql_variant null will be DBNull.Value)
            Debug.Assert(null != sqlVal, "invalid <null>, should be DBNull.Value");
            if (Convert.IsDBNull(sqlVal) || ((INullable)sqlVal).IsNull)
            {
                return(comVal);
            }

            switch (type)
            {
            case SqlDbType.BigInt:
                comVal = ((SqlInt64)sqlVal).Value;
                break;

            case SqlDbType.Binary:
            case SqlDbType.Timestamp:
            case SqlDbType.Image:
            case SqlDbType.VarBinary:
            // HACK!!!  We have an internal type for smallvarbinarys stored on TdsEnums.  We
            // store on TdsEnums instead of SqlDbType because we do not want to expose
            // this type to the user!
            case TdsEnums.SmallVarBinary:
                comVal = ((SqlBinary)sqlVal).Value;
                break;

            case SqlDbType.Bit:
                comVal = ((SqlBoolean)sqlVal).Value;
                break;

            case SqlDbType.Char:
            case SqlDbType.VarChar:
            case SqlDbType.Text:
            case SqlDbType.NChar:
            case SqlDbType.NVarChar:
            case SqlDbType.NText:
                comVal = ((SqlString)sqlVal).Value;
                break;

            case SqlDbType.DateTime:
            case SqlDbType.SmallDateTime:
                comVal = ((SqlDateTime)sqlVal).Value;
                break;

            case SqlDbType.Money:
            case SqlDbType.SmallMoney:
                comVal = ((SqlMoney)sqlVal).Value;
                break;

            case SqlDbType.Real:
                comVal = ((SqlSingle)sqlVal).Value;
                break;

            case SqlDbType.Float:
                comVal = ((SqlDouble)sqlVal).Value;
                break;

            case SqlDbType.Decimal:
                comVal = ((SqlDecimal)sqlVal).Value;
                break;

            case SqlDbType.Int:
                comVal = ((SqlInt32)sqlVal).Value;
                break;

            case SqlDbType.SmallInt:
                comVal = ((SqlInt16)sqlVal).Value;
                break;

            case SqlDbType.TinyInt:
                comVal = ((SqlByte)sqlVal).Value;
                break;

            case SqlDbType.UniqueIdentifier:
                comVal = ((SqlGuid)sqlVal).Value;
                break;

            case SqlDbType.Variant:
                comVal = MetaType.GetComValueFromSqlVariant(sqlVal);
                break;

            default:
                Debug.Assert(false, "unknown SqlDbType!  Can't create SQL type");
                break;
            }

            return(comVal);
        }