Export (0) Print
Expand All
This topic has not yet been rated - Rate this topic

SqlMetaData Class

Specifies and retrieves metadata information from parameters and columns of SqlDataRecord objects. This class cannot be inherited.

System.Object
  Microsoft.SqlServer.Server.SqlMetaData

Namespace:  Microsoft.SqlServer.Server
Assembly:  System.Data (in System.Data.dll)
'Declaration
Public NotInheritable Class SqlMetaData

The SqlMetaData type exposes the following members.

  NameDescription
Public methodSqlMetaData(String, SqlDbType)Initializes a new instance of the SqlMetaData class with the specified column name and type.
Public methodSqlMetaData(String, SqlDbType, Int64)Initializes a new instance of the SqlMetaData class with the specified column name, type, and maximum length.
Public methodSqlMetaData(String, SqlDbType, Type)Initializes a new instance of the SqlMetaData class with the specified column name, type, and user-defined type (UDT).
Public methodSqlMetaData(String, SqlDbType, Byte, Byte)Initializes a new instance of the SqlMetaData class with the specified column name, type, precision, and scale.
Public methodSqlMetaData(String, SqlDbType, Type, String)Initializes a new instance of the SqlMetaData class with the specified column name, user-defined type (UDT), and SQLServer type.
Public methodSqlMetaData(String, SqlDbType, Int64, Int64, SqlCompareOptions)Initializes a new instance of the SqlMetaData class with the specified column name, type, maximum length, locale, and compare options.
Public methodSqlMetaData(String, SqlDbType, String, String, String)Initializes a new instance of the SqlMetaData class with the specified column name, type, database name, owning schema, and object name.
Public methodSqlMetaData(String, SqlDbType, Boolean, Boolean, SortOrder, Int32)Initializes a new instance of the SqlMetaData class with the specified column name, and default server. This form of the constructor supports table-valued parameters by allowing you to specify if the column is unique in the table-valued parameter, the sort order for the column, and the ordinal of the sort column.
Public methodSqlMetaData(String, SqlDbType, Int64, Boolean, Boolean, SortOrder, Int32)Initializes a new instance of the SqlMetaData class with the specified column name, type, maximum length, and server default. This form of the constructor supports table-valued parameters by allowing you to specify if the column is unique in the table-valued parameter, the sort order for the column, and the ordinal of the sort column.
Public methodSqlMetaData(String, SqlDbType, Byte, Byte, Boolean, Boolean, SortOrder, Int32)Initializes a new instance of the SqlMetaData class with the specified column name, type, precision, scale, and server default. This form of the constructor supports table-valued parameters by allowing you to specify if the column is unique in the table-valued parameter, the sort order for the column, and the ordinal of the sort column.
Public methodSqlMetaData(String, SqlDbType, Int64, Byte, Byte, Int64, SqlCompareOptions, Type)Initializes a new instance of the SqlMetaData class with the specified column name, type, maximum length, precision, scale, locale ID, compare options, and user-defined type (UDT).
Public methodSqlMetaData(String, SqlDbType, Type, String, Boolean, Boolean, SortOrder, Int32)Initializes a new instance of the SqlMetaData class with the specified column name, type, user-defined type, SQL Server type, and server default. This form of the constructor supports table-valued parameters by allowing you to specify if the column is unique in the table-valued parameter, the sort order for the column, and the ordinal of the sort column.
Public methodSqlMetaData(String, SqlDbType, Int64, Int64, SqlCompareOptions, Boolean, Boolean, SortOrder, Int32)Initializes a new instance of the SqlMetaData class with the specified column name, type, maximum length, locale, compare options, and server default. This form of the constructor supports table-valued parameters by allowing you to specify if the column is unique in the table-valued parameter, the sort order for the column, and the ordinal of the sort column.
Public methodSqlMetaData(String, SqlDbType, String, String, String, Boolean, Boolean, SortOrder, Int32)Initializes a new instance of the SqlMetaData class with the specified column name, database name, owning schema, object name, and default server. This form of the constructor supports table-valued parameters by allowing you to specify if the column is unique in the table-valued parameter, the sort order for the column, and the ordinal of the sort column.
Public methodSqlMetaData(String, SqlDbType, Int64, Byte, Byte, Int64, SqlCompareOptions, Type, Boolean, Boolean, SortOrder, Int32)Initializes a new instance of the SqlMetaData class with the specified column name, type, maximum length, precision, scale, locale ID, compare options, and user-defined type (UDT). This form of the constructor supports table-valued parameters by allowing you to specify if the column is unique in the table-valued parameter, the sort order for the column, and the ordinal of the sort column.
Top
  NameDescription
Public propertyCompareOptionsGets the comparison rules used for the column or parameter.
Public propertyDbTypeGets the data type of the column or parameter.
Public propertyIsUniqueKeyIndicates if the column in the table-valued parameter is unique.
Public propertyLocaleIdGets the locale ID of the column or parameter.
Public propertyStatic memberMaxGets the length of text, ntext, and image data types.
Public propertyMaxLengthGets the maximum length of the column or parameter.
Public propertyNameGets the name of the column or parameter.
Public propertyPrecisionGets the precision of the column or parameter.
Public propertyScaleGets the scale of the column or parameter.
Public propertySortOrderReturns the sort order for a column.
Public propertySortOrdinalReturns the ordinal of the sort column.
Public propertySqlDbTypeGets the data type of the column or parameter.
Public propertyTypeGets the common language runtime (CLR) type of a user-defined type (UDT).
Public propertyTypeNameGets the three-part name of the user-defined type (UDT) or the SQL Server type represented by the instance.
Public propertyUseServerDefaultReports whether this column should use the default server value.
Public propertyXmlSchemaCollectionDatabaseGets the name of the database where the schema collection for this XML instance is located.
Public propertyXmlSchemaCollectionNameGets the name of the schema collection for this XML instance.
Public propertyXmlSchemaCollectionOwningSchemaGets the owning relational schema where the schema collection for this XML instance is located.
Top
  NameDescription
Public methodAdjust(Boolean)Validates the specified Boolean value against the metadata, and adjusts the value if necessary.
Public methodAdjust(Byte)Validates the specified Byte value against the metadata, and adjusts the value if necessary.
Public methodAdjust(Byte())Validates the specified array of Byte values against the metadata, and adjusts the value if necessary.
Public methodAdjust(Char)Validates the specified Char value against the metadata, and adjusts the value if necessary.
Public methodAdjust(Char())Validates the specified array of Char values against the metadata, and adjusts the value if necessary.
Public methodAdjust(DateTime)Validates the specified DateTime value against the metadata, and adjusts the value if necessary.
Public methodAdjust(DateTimeOffset)Validates the specified DateTimeOffset value against the metadata, and adjusts the value if necessary.
Public methodAdjust(Decimal)Validates the specified Decimal value against the metadata, and adjusts the value if necessary.
Public methodAdjust(Double)Validates the specified Double value against the metadata, and adjusts the value if necessary.
Public methodAdjust(Guid)Validates the specified Guid value against the metadata, and adjusts the value if necessary.
Public methodAdjust(Int16)Validates the specified Int16 value against the metadata, and adjusts the value if necessary.
Public methodAdjust(Int32)Validates the specified Int32 value against the metadata, and adjusts the value if necessary.
Public methodAdjust(Int64)Validates the specified Int64 value against the metadata, and adjusts the value if necessary.
Public methodAdjust(Object)Validates the specified Object value against the metadata, and adjusts the value if necessary.
Public methodAdjust(Single)Validates the specified Single value against the metadata, and adjusts the value if necessary.
Public methodAdjust(SqlBinary)Validates the specified SqlBinary value against the metadata, and adjusts the value if necessary.
Public methodAdjust(SqlBoolean)Validates the specified SqlBoolean value against the metadata, and adjusts the value if necessary.
Public methodAdjust(SqlByte)Validates the specified SqlByte value against the metadata, and adjusts the value if necessary.
Public methodAdjust(SqlBytes)Validates the specified SqlBytes value against the metadata, and adjusts the value if necessary.
Public methodAdjust(SqlChars)Validates the specified SqlChars value against the metadata, and adjusts the value if necessary.
Public methodAdjust(SqlDateTime)Validates the specified SqlDateTime value against the metadata, and adjusts the value if necessary.
Public methodAdjust(SqlDecimal)Validates the specified SqlDecimal value against the metadata, and adjusts the value if necessary.
Public methodAdjust(SqlDouble)Validates the specified SqlDouble value against the metadata, and adjusts the value if necessary.
Public methodAdjust(SqlGuid)Validates the specified SqlGuid value against the metadata, and adjusts the value if necessary.
Public methodAdjust(SqlInt16)Validates the specified SqlInt16 value against the metadata, and adjusts the value if necessary.
Public methodAdjust(SqlInt32)Validates the specified SqlInt32 value against the metadata, and adjusts the value if necessary.
Public methodAdjust(SqlInt64)Validates the specified SqlInt64 value against the metadata, and adjusts the value if necessary.
Public methodAdjust(SqlMoney)Validates the specified SqlMoney value against the metadata, and adjusts the value if necessary.
Public methodAdjust(SqlSingle)Validates the specified SqlSingle value against the metadata, and adjusts the value if necessary.
Public methodAdjust(SqlString)Validates the specified SqlString value against the metadata, and adjusts the value if necessary.
Public methodAdjust(SqlXml)Validates the specified SqlXml value against the metadata, and adjusts the value if necessary.
Public methodAdjust(String)Validates the specified String value against the metadata, and adjusts the value if necessary.
Public methodAdjust(TimeSpan)Validates the specified TimeSpan value against the metadata, and adjusts the value if necessary.
Public methodEquals(Object)Determines whether the specified object is equal to the current object. (Inherited from Object.)
Public methodGetHashCodeServes as the default hash function. (Inherited from Object.)
Public methodGetTypeGets the Type of the current instance. (Inherited from Object.)
Public methodStatic memberInferFromValueInfers the metadata from the specified object and returns it as a SqlMetaData instance.
Public methodToStringReturns a string that represents the current object. (Inherited from Object.)
Top

The following example shows the creation of several SqlMetaData objects, which describe the column metadata of a record, and the creation of a SqlDataRecord. The column values of the SqlDataRecord are set and the SqlDataRecord is sent to the calling program using the SqlContext class.

<Microsoft.SqlServer.Server.SqlProcedure()> _
Public Shared Sub CreateNewRecord()

   ' Variables. 
   Dim column1Info As SqlMetaData 
   Dim column2Info As SqlMetaData
   Dim column3Info As SqlMetaData
   Dim record As SqlDataRecord

   ' Create the column metadata.
   column1Info = new SqlMetaData("Column1", SqlDbType.NVarChar, 12)
   column2Info = new SqlMetaData("Column2", SqlDbType.Int)
   column3Info = new SqlMetaData("Column3", SqlDbType.DateTime)

   ' Create a new record with the column metadata.      
   record = new SqlDataRecord(new SqlMetaData() { column1Info, _
                                                  column2Info, _
                                                  column3Info })

   ' Set the record fields.
   record.SetString(0, "Hello World!")
   record.SetInt32(1, 42)
   record.SetDateTime(2, DateTime.Now)

   ' Send the record to the calling program.
   SqlContext.Pipe.Send(record)

End Sub

.NET Framework

Supported in: 4.5.1, 4.5, 4, 3.5, 3.0, 2.0

.NET Framework Client Profile

Supported in: 4, 3.5 SP1

Windows Phone 8.1, Windows Phone 8, Windows 8.1, Windows Server 2012 R2, Windows 8, Windows Server 2012, Windows 7, Windows Vista SP2, Windows Server 2008 (Server Core Role not supported), Windows Server 2008 R2 (Server Core Role supported with SP1 or later; Itanium not supported)

The .NET Framework does not support all versions of every platform. For a list of the supported versions, see .NET Framework System Requirements.

Any public static (Shared in Visual Basic) members of this type are thread safe. Any instance members are not guaranteed to be thread safe.
Did you find this helpful?
(1500 characters remaining)
Thank you for your feedback
Show:
© 2014 Microsoft. All rights reserved.