当前位置: 首页>>代码示例>>C#>>正文


C# SqlClient.MetaType类代码示例

本文整理汇总了C#中System.Data.SqlClient.MetaType的典型用法代码示例。如果您正苦于以下问题:C# MetaType类的具体用法?C# MetaType怎么用?C# MetaType使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。


MetaType类属于System.Data.SqlClient命名空间,在下文中一共展示了MetaType类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: DeleteMetaInfo

 public static void DeleteMetaInfo(int objId, MetaType type)
 {
     SQLDataAccess.ExecuteNonQuery("DELETE FROM [SEO].[MetaInfo] WHERE [email protected] and [email protected]",
                                   CommandType.Text,
                                   new SqlParameter("@objId", objId),
                                   new SqlParameter("@type", type.ToString()));
 }
开发者ID:AzarinSergey,项目名称:learn,代码行数:7,代码来源:MetaInfoService.cs

示例2: CoerceValue

 internal static object CoerceValue(object value, MetaType destinationType)
 {
     if ((value != null) && (DBNull.Value != value))
     {
         Type c = value.GetType();
         bool flag = true;
         if ((value is INullable) && ((INullable) value).IsNull)
         {
             flag = false;
         }
         if (!flag || !(typeof(object) != destinationType.ClassType))
         {
             return value;
         }
         if (((c == destinationType.ClassType) || (c == destinationType.SqlType)) && (System.Data.SqlDbType.Xml != destinationType.SqlDbType))
         {
             return value;
         }
         try
         {
             if (typeof(string) == destinationType.ClassType)
             {
                 if (typeof(SqlXml) == c)
                 {
                     value = MetaType.GetStringFromXml(((SqlXml) value).CreateReader());
                     return value;
                 }
                 if (typeof(SqlString) != c)
                 {
                     if (typeof(XmlReader).IsAssignableFrom(c))
                     {
                         value = MetaType.GetStringFromXml((XmlReader) value);
                         return value;
                     }
                     if (typeof(char[]) == c)
                     {
                         value = new string((char[]) value);
                         return value;
                     }
                     if (typeof(SqlChars) == c)
                     {
                         SqlChars chars = (SqlChars) value;
                         value = new string(chars.Value);
                         return value;
                     }
                     value = Convert.ChangeType(value, destinationType.ClassType, null);
                 }
                 return value;
             }
             if ((System.Data.DbType.Currency == destinationType.DbType) && (typeof(string) == c))
             {
                 value = decimal.Parse((string) value, NumberStyles.Currency, null);
                 return value;
             }
             if ((typeof(SqlBytes) == c) && (typeof(byte[]) == destinationType.ClassType))
             {
                 SqlBytes bytes1 = (SqlBytes) value;
                 return value;
             }
             if ((typeof(string) == c) && (System.Data.SqlDbType.Time == destinationType.SqlDbType))
             {
                 value = TimeSpan.Parse((string) value);
                 return value;
             }
             if ((typeof(string) == c) && (System.Data.SqlDbType.DateTimeOffset == destinationType.SqlDbType))
             {
                 value = DateTimeOffset.Parse((string) value, null);
                 return value;
             }
             if ((typeof(DateTime) == c) && (System.Data.SqlDbType.DateTimeOffset == destinationType.SqlDbType))
             {
                 value = new DateTimeOffset((DateTime) value);
                 return value;
             }
             if ((0xf3 == destinationType.TDSType) && (((value is DataTable) || (value is DbDataReader)) || (value is IEnumerable<SqlDataRecord>)))
             {
                 return value;
             }
             value = Convert.ChangeType(value, destinationType.ClassType, null);
         }
         catch (Exception exception)
         {
             if (!ADP.IsCatchableExceptionType(exception))
             {
                 throw;
             }
             throw ADP.ParameterConversionFailed(value, destinationType.ClassType, exception);
         }
     }
     return value;
 }
开发者ID:pritesh-mandowara-sp,项目名称:DecompliedDotNetLibraries,代码行数:91,代码来源:SqlParameter.cs

示例3: WriteUnterminatedValue

        // For MAX types, this method can only write everything in one big chunk. If multiple
        // chunk writes needed, please use WritePlpBytes/WritePlpChars
        private Task WriteUnterminatedValue(object value, MetaType type, byte scale, int actualLength, int encodingByteSize, int offset, TdsParserStateObject stateObj, int paramSize, bool isDataFeed)
        {
            Debug.Assert((null != value) && (DBNull.Value != value), "unexpected missing or empty object");

            // parameters are always sent over as BIG or N types
            switch (type.NullableType)
            {
                case TdsEnums.SQLFLTN:
                    if (type.FixedLength == 4)
                        WriteFloat((Single)value, stateObj);
                    else
                    {
                        Debug.Assert(type.FixedLength == 8, "Invalid length for SqlDouble type!");
                        WriteDouble((Double)value, stateObj);
                    }

                    break;

                case TdsEnums.SQLBIGBINARY:
                case TdsEnums.SQLBIGVARBINARY:
                case TdsEnums.SQLIMAGE:
                case TdsEnums.SQLUDT:
                    {
                        // An array should be in the object
                        Debug.Assert(isDataFeed || value is byte[], "Value should be an array of bytes");
                        Debug.Assert(!isDataFeed || value is StreamDataFeed, "Value should be a stream");

                        if (isDataFeed)
                        {
                            Debug.Assert(type.IsPlp, "Stream assigned to non-PLP was not converted!");
                            return NullIfCompletedWriteTask(WriteStreamFeed((StreamDataFeed)value, stateObj, paramSize));
                        }
                        else
                        {
                            if (type.IsPlp)
                            {
                                WriteInt(actualLength, stateObj);               // chunk length                        
                            }
                            return stateObj.WriteByteArray((byte[])value, actualLength, offset, canAccumulate: false);
                        }
                    }

                case TdsEnums.SQLUNIQUEID:
                    {
                        System.Guid guid = (System.Guid)value;
                        byte[] b = guid.ToByteArray();

                        Debug.Assert((actualLength == b.Length) && (actualLength == 16), "Invalid length for guid type in com+ object");
                        stateObj.WriteByteArray(b, actualLength, 0);
                        break;
                    }

                case TdsEnums.SQLBITN:
                    {
                        Debug.Assert(type.FixedLength == 1, "Invalid length for SqlBoolean type");
                        if ((bool)value == true)
                            stateObj.WriteByte(1);
                        else
                            stateObj.WriteByte(0);

                        break;
                    }

                case TdsEnums.SQLINTN:
                    if (type.FixedLength == 1)
                        stateObj.WriteByte((byte)value);
                    else if (type.FixedLength == 2)
                        WriteShort((Int16)value, stateObj);
                    else if (type.FixedLength == 4)
                        WriteInt((Int32)value, stateObj);
                    else
                    {
                        Debug.Assert(type.FixedLength == 8, "invalid length for SqlIntN type:  " + type.FixedLength.ToString(CultureInfo.InvariantCulture));
                        WriteLong((Int64)value, stateObj);
                    }

                    break;

                case TdsEnums.SQLBIGCHAR:
                case TdsEnums.SQLBIGVARCHAR:
                case TdsEnums.SQLTEXT:
                    {
                        Debug.Assert(!isDataFeed || (value is TextDataFeed || value is XmlDataFeed), "Value must be a TextReader or XmlReader");
                        Debug.Assert(isDataFeed || (value is string || value is byte[]), "Value is a byte array or string");

                        if (isDataFeed)
                        {
                            Debug.Assert(type.IsPlp, "Stream assigned to non-PLP was not converted!");
                            TextDataFeed tdf = value as TextDataFeed;
                            if (tdf == null)
                            {
                                return NullIfCompletedWriteTask(WriteXmlFeed((XmlDataFeed)value, stateObj, needBom: true, encoding: _defaultEncoding, size: paramSize));
                            }
                            else
                            {
                                return NullIfCompletedWriteTask(WriteTextFeed(tdf, _defaultEncoding, false, stateObj, paramSize));
                            }
                        }
//.........这里部分代码省略.........
开发者ID:nnyamhon,项目名称:corefx,代码行数:101,代码来源:TdsParser.cs

示例4: WriteUnterminatedSqlValue

        // For MAX types, this method can only write everything in one big chunk. If multiple
        // chunk writes needed, please use WritePlpBytes/WritePlpChars
        private Task WriteUnterminatedSqlValue(object value, MetaType type, int actualLength, int codePageByteSize, int offset, TdsParserStateObject stateObj)
        {
            Debug.Assert(((type.NullableType == TdsEnums.SQLXMLTYPE) ||
                   (value is INullable && !((INullable)value).IsNull)),
                   "unexpected null SqlType!");

            // parameters are always sent over as BIG or N types
            switch (type.NullableType)
            {
                case TdsEnums.SQLFLTN:
                    if (type.FixedLength == 4)
                        WriteFloat(((SqlSingle)value).Value, stateObj);
                    else
                    {
                        Debug.Assert(type.FixedLength == 8, "Invalid length for SqlDouble type!");
                        WriteDouble(((SqlDouble)value).Value, stateObj);
                    }

                    break;

                case TdsEnums.SQLBIGBINARY:
                case TdsEnums.SQLBIGVARBINARY:
                case TdsEnums.SQLIMAGE:
                    {
                        if (type.IsPlp)
                        {
                            WriteInt(actualLength, stateObj);               // chunk length
                        }

                        if (value is SqlBinary)
                        {
                            return stateObj.WriteByteArray(((SqlBinary)value).Value, actualLength, offset, canAccumulate: false);
                        }
                        else
                        {
                            Debug.Assert(value is SqlBytes);
                            return stateObj.WriteByteArray(((SqlBytes)value).Value, actualLength, offset, canAccumulate: false);
                        }
                    }

                case TdsEnums.SQLUNIQUEID:
                    {
                        byte[] b = ((SqlGuid)value).ToByteArray();

                        Debug.Assert((actualLength == b.Length) && (actualLength == 16), "Invalid length for guid type in com+ object");
                        stateObj.WriteByteArray(b, actualLength, 0);
                        break;
                    }

                case TdsEnums.SQLBITN:
                    {
                        Debug.Assert(type.FixedLength == 1, "Invalid length for SqlBoolean type");
                        if (((SqlBoolean)value).Value == true)
                            stateObj.WriteByte(1);
                        else
                            stateObj.WriteByte(0);

                        break;
                    }

                case TdsEnums.SQLINTN:
                    if (type.FixedLength == 1)
                        stateObj.WriteByte(((SqlByte)value).Value);
                    else
                        if (type.FixedLength == 2)
                        WriteShort(((SqlInt16)value).Value, stateObj);
                    else
                            if (type.FixedLength == 4)
                        WriteInt(((SqlInt32)value).Value, stateObj);
                    else
                    {
                        Debug.Assert(type.FixedLength == 8, "invalid length for SqlIntN type:  " + type.FixedLength.ToString(CultureInfo.InvariantCulture));
                        WriteLong(((SqlInt64)value).Value, stateObj);
                    }

                    break;

                case TdsEnums.SQLBIGCHAR:
                case TdsEnums.SQLBIGVARCHAR:
                case TdsEnums.SQLTEXT:
                    if (type.IsPlp)
                    {
                        WriteInt(codePageByteSize, stateObj);               // chunk length
                    }
                    if (value is SqlChars)
                    {
                        String sch = new String(((SqlChars)value).Value);

                        return WriteEncodingChar(sch, actualLength, offset, _defaultEncoding, stateObj, canAccumulate: false);
                    }
                    else
                    {
                        Debug.Assert(value is SqlString);
                        return WriteEncodingChar(((SqlString)value).Value, actualLength, offset, _defaultEncoding, stateObj, canAccumulate: false);
                    }


                case TdsEnums.SQLNCHAR:
//.........这里部分代码省略.........
开发者ID:nnyamhon,项目名称:corefx,代码行数:101,代码来源:TdsParser.cs

示例5: GetTerminationTask

 private Task GetTerminationTask(Task unterminatedWriteTask, object value, MetaType type, int actualLength, TdsParserStateObject stateObj, bool isDataFeed)
 {
     if (type.IsPlp && ((actualLength > 0) || isDataFeed))
     {
         if (unterminatedWriteTask == null)
         {
             WriteInt(0, stateObj);
             return null;
         }
         else
         {
             return AsyncHelper.CreateContinuationTask<int, TdsParserStateObject>(unterminatedWriteTask,
                 WriteInt, 0, stateObj,
                 connectionToDoom: _connHandler);
         }
     }
     else
     {
         return unterminatedWriteTask;
     }
 }
开发者ID:nnyamhon,项目名称:corefx,代码行数:21,代码来源:TdsParser.cs

示例6: IsNull

        private bool IsNull(MetaType mt, ulong length)
        {
            // null bin and char types have a length of -1 to represent null
            if (mt.IsPlp)
            {
                return (TdsEnums.SQL_PLP_NULL == length);
            }

            // HOTFIX #50000415: for image/text, 0xFFFF is the length, not representing null
            if ((TdsEnums.VARNULL == length) && !mt.IsLong)
            {
                return true;
            }

            // other types have a length of 0 to represent null
            // long and non-PLP types will always return false because these types are either char or binary
            // this is expected since for long and non-plp types isnull is checked based on textptr field and not the length
            return ((TdsEnums.FIXEDNULL == length) && !mt.IsCharType && !mt.IsBinType);
        }
开发者ID:nnyamhon,项目名称:corefx,代码行数:19,代码来源:TdsParser.cs

示例7: BulkLoadCannotConvertValue

 internal static Exception BulkLoadCannotConvertValue(Type sourcetype, MetaType metatype, Exception e)
 {
     return ADP.InvalidOperation(Res.GetString("SQL_BulkLoadCannotConvertValue", new object[] { sourcetype.Name, metatype.TypeName }), e);
 }
开发者ID:pritesh-mandowara-sp,项目名称:DecompliedDotNetLibraries,代码行数:4,代码来源:SQL.cs

示例8: GetMaxMetaTypeFromMetaType

        internal static MetaType GetMaxMetaTypeFromMetaType(MetaType mt)
        {
            System.Data.SqlDbType sqlDbType = mt.SqlDbType;
            if (sqlDbType <= System.Data.SqlDbType.NVarChar)
            {
                switch (sqlDbType)
                {
                    case System.Data.SqlDbType.Binary:
                        goto Label_004F;

                    case System.Data.SqlDbType.Bit:
                        return mt;

                    case System.Data.SqlDbType.Char:
                        goto Label_0055;

                    case System.Data.SqlDbType.NChar:
                    case System.Data.SqlDbType.NVarChar:
                        return MetaMaxNVarChar;

                    case System.Data.SqlDbType.NText:
                        return mt;
                }
                return mt;
            }
            switch (sqlDbType)
            {
                case System.Data.SqlDbType.VarBinary:
                    break;

                case System.Data.SqlDbType.VarChar:
                    goto Label_0055;

                case System.Data.SqlDbType.Udt:
                    return MetaMaxUdt;

                default:
                    return mt;
            }
        Label_004F:
            return MetaMaxVarBinary;
        Label_0055:
            return MetaMaxVarChar;
        }
开发者ID:pritesh-mandowara-sp,项目名称:DecompliedDotNetLibraries,代码行数:44,代码来源:MetaType.cs

示例9: GetVersionedMetaType

 private MetaType GetVersionedMetaType(MetaType actualMetaType)
 {
     if (actualMetaType == MetaType.MetaUdt)
     {
         return MetaType.MetaVarBinary;
     }
     if (actualMetaType == MetaType.MetaXml)
     {
         return MetaType.MetaNText;
     }
     if (actualMetaType == MetaType.MetaMaxVarBinary)
     {
         return MetaType.MetaImage;
     }
     if (actualMetaType == MetaType.MetaMaxVarChar)
     {
         return MetaType.MetaText;
     }
     if (actualMetaType == MetaType.MetaMaxNVarChar)
     {
         return MetaType.MetaNText;
     }
     return actualMetaType;
 }
开发者ID:pritesh-mandowara-sp,项目名称:DecompliedDotNetLibraries,代码行数:24,代码来源:SqlDataReader.cs

示例10: GetMetadataForTypeInfo

        /// <summary>
        /// Get SMI Metadata to write out type_info stream.
        /// </summary>
        /// <returns></returns>
        internal MSS.SmiParameterMetaData GetMetadataForTypeInfo() {
            ParameterPeekAheadValue peekAhead = null;

            if (_internalMetaType == null) {
                _internalMetaType = GetMetaTypeOnly();
            }

            return MetaDataForSmi(out peekAhead);
        }
开发者ID:uQr,项目名称:referencesource,代码行数:13,代码来源:SqlParameter.cs

示例11: ValidateTypeLengths

        // func will change type to that with a 4 byte length if the type has a two
        // byte length and a parameter length > than that expressable in 2 bytes
        internal MetaType ValidateTypeLengths(bool yukonOrNewer) {
            MetaType mt = InternalMetaType;
            // MDAC 




            if ((SqlDbType.Udt != mt.SqlDbType) && (false == mt.IsFixed) && (false == mt.IsLong)) { // if type has 2 byte length
                long actualSizeInBytes = this.GetActualSize();
                long sizeInCharacters = this.Size;

                // 

















                long maxSizeInBytes = 0;
                if ((mt.IsNCharType) && (yukonOrNewer))
                    maxSizeInBytes = ((sizeInCharacters * sizeof(char)) > actualSizeInBytes) ? sizeInCharacters * sizeof(char) : actualSizeInBytes;
                else
                {
                    // Notes:
                    // Elevation from (n)(var)char (4001+) to (n)text succeeds without failure only with Yukon and greater.
                    // it fails in sql server 2000
                    maxSizeInBytes = (sizeInCharacters > actualSizeInBytes) ? sizeInCharacters : actualSizeInBytes;
                }

                if ((maxSizeInBytes > TdsEnums.TYPE_SIZE_LIMIT) || (_coercedValueIsDataFeed) || 
                    (sizeInCharacters == -1) || (actualSizeInBytes == -1)) { // is size > size able to be described by 2 bytes
                    if (yukonOrNewer) {
                        // Convert the parameter to its max type
                        mt = MetaType.GetMaxMetaTypeFromMetaType(mt);
                        _metaType = mt;
                        InternalMetaType = mt;
                        if (!mt.IsPlp) {
                            if (mt.SqlDbType == SqlDbType.Xml) {
                                throw ADP.InvalidMetaDataValue();     //Xml should always have IsPartialLength = true
                            }
                            if (mt.SqlDbType == SqlDbType.NVarChar 
                             || mt.SqlDbType == SqlDbType.VarChar 
                             || mt.SqlDbType == SqlDbType.VarBinary) {
                                Size = (int)(SmiMetaData.UnlimitedMaxLengthIndicator);
                            }
                        }
                    }
                    else {
                        switch (mt.SqlDbType) { // widening the SqlDbType is automatic
                        case SqlDbType.Binary:
                        case SqlDbType.VarBinary:
                            mt = MetaType.GetMetaTypeFromSqlDbType (SqlDbType.Image, false);
                            _metaType = mt; // do not use SqlDbType property which calls PropertyTypeChanging resetting coerced value
                            InternalMetaType = mt;
                            break;
                        case SqlDbType.Char:
                        case SqlDbType.VarChar:
                            mt = MetaType.GetMetaTypeFromSqlDbType (SqlDbType.Text, false);
                            _metaType = mt;
                            InternalMetaType = mt;
                            break;
                        case SqlDbType.NChar:
                        case SqlDbType.NVarChar:
                            mt = MetaType.GetMetaTypeFromSqlDbType (SqlDbType.NText, false);
                            _metaType = mt;
                            InternalMetaType = mt;
                            break;
                        default:
                            Debug.Assert(false, "Missed metatype in SqlCommand.BuildParamList()");
                            break;
                        }
                    }
                }
            }
            return mt;
        }
开发者ID:uQr,项目名称:referencesource,代码行数:89,代码来源:SqlParameter.cs

示例12: GetMaxMetaTypeFromMetaType

 internal static MetaType GetMaxMetaTypeFromMetaType(MetaType mt)
 {
     // if we can't map it, we need to throw
     switch (mt.SqlDbType)
     {
         case SqlDbType.VarBinary:
         case SqlDbType.Binary:
             return MetaMaxVarBinary;
         case SqlDbType.VarChar:
         case SqlDbType.Char:
             return MetaMaxVarChar;
         case SqlDbType.NVarChar:
         case SqlDbType.NChar:
             return MetaMaxNVarChar;
         case SqlDbType.Udt:
             Debug.Assert(false, "UDT is not supported");
             return mt;
         default:
             return mt;
     }
 }
开发者ID:nnyamhon,项目名称:corefx,代码行数:21,代码来源:SqlEnums.cs

示例13: ValidateTypeLengths

        internal MetaType ValidateTypeLengths(bool yukonOrNewer)
        {
            MetaType internalMetaType = this.InternalMetaType;
            if (((System.Data.SqlDbType.Udt != internalMetaType.SqlDbType) && !internalMetaType.IsFixed) && !internalMetaType.IsLong)
            {
                long actualSize = this.GetActualSize();
                long size = this.Size;
                long num3 = 0L;
                if (internalMetaType.IsNCharType && yukonOrNewer)
                {
                    num3 = ((size * 2L) > actualSize) ? (size * 2L) : actualSize;
                }
                else
                {
                    num3 = (size > actualSize) ? size : actualSize;
                }
                if (((num3 <= 0x1f40L) && (size != -1L)) && (actualSize != -1L))
                {
                    return internalMetaType;
                }
                if (yukonOrNewer)
                {
                    internalMetaType = MetaType.GetMaxMetaTypeFromMetaType(internalMetaType);
                    this._metaType = internalMetaType;
                    this.InternalMetaType = internalMetaType;
                    if (!internalMetaType.IsPlp)
                    {
                        if (internalMetaType.SqlDbType == System.Data.SqlDbType.Xml)
                        {
                            throw ADP.InvalidMetaDataValue();
                        }
                        if (((internalMetaType.SqlDbType != System.Data.SqlDbType.NVarChar) && (internalMetaType.SqlDbType != System.Data.SqlDbType.VarChar)) && (internalMetaType.SqlDbType != System.Data.SqlDbType.VarBinary))
                        {
                            return internalMetaType;
                        }
                        this.Size = -1;
                    }
                    return internalMetaType;
                }
                switch (internalMetaType.SqlDbType)
                {
                    case System.Data.SqlDbType.Binary:
                    case System.Data.SqlDbType.VarBinary:
                        internalMetaType = MetaType.GetMetaTypeFromSqlDbType(System.Data.SqlDbType.Image, false);
                        this._metaType = internalMetaType;
                        this.InternalMetaType = internalMetaType;
                        return internalMetaType;

                    case System.Data.SqlDbType.Bit:
                        return internalMetaType;

                    case System.Data.SqlDbType.Char:
                    case System.Data.SqlDbType.VarChar:
                        internalMetaType = MetaType.GetMetaTypeFromSqlDbType(System.Data.SqlDbType.Text, false);
                        this._metaType = internalMetaType;
                        this.InternalMetaType = internalMetaType;
                        return internalMetaType;

                    case System.Data.SqlDbType.NChar:
                    case System.Data.SqlDbType.NVarChar:
                        internalMetaType = MetaType.GetMetaTypeFromSqlDbType(System.Data.SqlDbType.NText, false);
                        this._metaType = internalMetaType;
                        this.InternalMetaType = internalMetaType;
                        return internalMetaType;

                    case System.Data.SqlDbType.NText:
                        return internalMetaType;
                }
            }
            return internalMetaType;
        }
开发者ID:pritesh-mandowara-sp,项目名称:DecompliedDotNetLibraries,代码行数:71,代码来源:SqlParameter.cs

示例14: Validate

 internal void Validate(int index, bool isCommandProc)
 {
     MetaType metaTypeOnly = this.GetMetaTypeOnly();
     this._internalMetaType = metaTypeOnly;
     if ((((ADP.IsDirection(this, ParameterDirection.Output) && !ADP.IsDirection(this, ParameterDirection.ReturnValue)) && (!metaTypeOnly.IsFixed && !this.ShouldSerializeSize())) && ((this._value == null) || Convert.IsDBNull(this._value))) && (((this.SqlDbType != System.Data.SqlDbType.Timestamp) && (this.SqlDbType != System.Data.SqlDbType.Udt)) && ((this.SqlDbType != System.Data.SqlDbType.Xml) && !metaTypeOnly.IsVarTime)))
     {
         throw ADP.UninitializedParameterSize(index, metaTypeOnly.ClassType);
     }
     if ((metaTypeOnly.SqlDbType != System.Data.SqlDbType.Udt) && (this.Direction != ParameterDirection.Output))
     {
         this.GetCoercedValue();
     }
     if (metaTypeOnly.SqlDbType == System.Data.SqlDbType.Udt)
     {
         if (ADP.IsEmpty(this.UdtTypeName))
         {
             throw SQL.MustSetUdtTypeNameForUdtParams();
         }
     }
     else if (!ADP.IsEmpty(this.UdtTypeName))
     {
         throw SQL.UnexpectedUdtTypeNameForNonUdtParams();
     }
     if (metaTypeOnly.SqlDbType == System.Data.SqlDbType.Structured)
     {
         if (!isCommandProc && ADP.IsEmpty(this.TypeName))
         {
             throw SQL.MustSetTypeNameForParam(metaTypeOnly.TypeName, this.ParameterName);
         }
         if (ParameterDirection.Input != this.Direction)
         {
             throw SQL.UnsupportedTVPOutputParameter(this.Direction, this.ParameterName);
         }
         if (DBNull.Value == this.GetCoercedValue())
         {
             throw SQL.DBNullNotSupportedForTVPValues(this.ParameterName);
         }
     }
     else if (!ADP.IsEmpty(this.TypeName))
     {
         throw SQL.UnexpectedTypeNameForNonStructParams(this.ParameterName);
     }
 }
开发者ID:pritesh-mandowara-sp,项目名称:DecompliedDotNetLibraries,代码行数:43,代码来源:SqlParameter.cs

示例15: CoerceValue

        // Coerced Value is also used in SqlBulkCopy.ConvertValue(object value, _SqlMetaData metadata)
        internal static object CoerceValue(object value, MetaType destinationType, out bool coercedToDataFeed, out bool typeChanged, bool allowStreaming = true)
        {
            Debug.Assert(!(value is DataFeed), "Value provided should not already be a data feed");
            Debug.Assert(!ADP.IsNull(value), "Value provided should not be null");
            Debug.Assert(null != destinationType, "null destinationType");

            coercedToDataFeed = false;
            typeChanged = false;
            Type currentType = value.GetType();

            if ((typeof(object) != destinationType.ClassType) &&
                    (currentType != destinationType.ClassType) &&
                    ((currentType != destinationType.SqlType) || (SqlDbType.Xml == destinationType.SqlDbType)))
            {   // Special case for Xml types (since we need to convert SqlXml into a string)
                try
                {
                    // Assume that the type changed
                    typeChanged = true;
                    if ((typeof(string) == destinationType.ClassType))
                    {
                        // For Xml data, destination Type is always string
                        if (typeof(SqlXml) == currentType)
                        {
                            value = MetaType.GetStringFromXml((XmlReader)(((SqlXml)value).CreateReader()));
                        }
                        else if (typeof(SqlString) == currentType)
                        {
                            typeChanged = false;   // Do nothing
                        }
                        else if (typeof(XmlReader).IsAssignableFrom(currentType))
                        {
                            if (allowStreaming)
                            {
                                coercedToDataFeed = true;
                                value = new XmlDataFeed((XmlReader)value);
                            }
                            else
                            {
                                value = MetaType.GetStringFromXml((XmlReader)value);
                            }
                        }
                        else if (typeof(char[]) == currentType)
                        {
                            value = new string((char[])value);
                        }
                        else if (typeof(SqlChars) == currentType)
                        {
                            value = new string(((SqlChars)value).Value);
                        }
                        else if (value is TextReader && allowStreaming)
                        {
                            coercedToDataFeed = true;
                            value = new TextDataFeed((TextReader)value);
                        }
                        else
                        {
                            value = Convert.ChangeType(value, destinationType.ClassType, (IFormatProvider)null);
                        }
                    }
                    else if ((DbType.Currency == destinationType.DbType) && (typeof(string) == currentType))
                    {
                        value = Decimal.Parse((string)value, NumberStyles.Currency, (IFormatProvider)null); // WebData 99376
                    }
                    else if ((typeof(SqlBytes) == currentType) && (typeof(byte[]) == destinationType.ClassType))
                    {
                        typeChanged = false;    // Do nothing
                    }
                    else if ((typeof(string) == currentType) && (SqlDbType.Time == destinationType.SqlDbType))
                    {
                        value = TimeSpan.Parse((string)value);
                    }
                    else if ((typeof(string) == currentType) && (SqlDbType.DateTimeOffset == destinationType.SqlDbType))
                    {
                        value = DateTimeOffset.Parse((string)value, (IFormatProvider)null);
                    }
                    else if ((typeof(DateTime) == currentType) && (SqlDbType.DateTimeOffset == destinationType.SqlDbType))
                    {
                        value = new DateTimeOffset((DateTime)value);
                    }
                    else if (TdsEnums.SQLTABLE == destinationType.TDSType && (
                                value is DbDataReader ||
                                value is System.Collections.Generic.IEnumerable<SqlDataRecord>))
                    {
                        // no conversion for TVPs.
                        typeChanged = false;
                    }
                    else if (destinationType.ClassType == typeof(byte[]) && value is Stream && allowStreaming)
                    {
                        coercedToDataFeed = true;
                        value = new StreamDataFeed((Stream)value);
                    }
                    else
                    {
                        value = Convert.ChangeType(value, destinationType.ClassType, (IFormatProvider)null);
                    }
                }
                catch (Exception e)
                {
                    if (!ADP.IsCatchableExceptionType(e))
//.........这里部分代码省略.........
开发者ID:rajeevkb,项目名称:corefx,代码行数:101,代码来源:SqlParameter.cs


注:本文中的System.Data.SqlClient.MetaType类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。