1 out of 1 rated this helpful - 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)
public sealed class SqlMetaData

The SqlMetaData type exposes the following members.

  Name Description
Public method SqlMetaData(String, SqlDbType) Initializes a new instance of the SqlMetaData class with the specified column name and type.
Public method SqlMetaData(String, SqlDbType, Int64) Initializes a new instance of the SqlMetaData class with the specified column name, type, and maximum length.
Public method SqlMetaData(String, SqlDbType, Type) Initializes a new instance of the SqlMetaData class with the specified column name, type, and user-defined type (UDT).
Public method SqlMetaData(String, SqlDbType, Byte, Byte) Initializes a new instance of the SqlMetaData class with the specified column name, type, precision, and scale.
Public method SqlMetaData(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 method SqlMetaData(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 method SqlMetaData(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 method SqlMetaData(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 method SqlMetaData(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 method SqlMetaData(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 method SqlMetaData(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 method SqlMetaData(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 method SqlMetaData(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 method SqlMetaData(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 method SqlMetaData(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
  Name Description
Public property CompareOptions Gets the comparison rules used for the column or parameter.
Public property DbType Gets the data type of the column or parameter.
Public property IsUniqueKey Indicates if the column in the table-valued parameter is unique.
Public property LocaleId Gets the locale ID of the column or parameter.
Public property Static member Max Gets the length of text, ntext, and image data types.
Public property MaxLength Gets the maximum length of the column or parameter.
Public property Name Gets the name of the column or parameter.
Public property Precision Gets the precision of the column or parameter.
Public property Scale Gets the scale of the column or parameter.
Public property SortOrder Returns the sort order for a column.
Public property SortOrdinal Returns the ordinal of the sort column.
Public property SqlDbType Gets the data type of the column or parameter.
Public property Type Gets the common language runtime (CLR) type of a user-defined type (UDT).
Public property TypeName Gets the three-part name of the user-defined type (UDT) or the SQL Server type represented by the instance.
Public property UseServerDefault Reports whether this column should use the default server value.
Public property XmlSchemaCollectionDatabase Gets the name of the database where the schema collection for this XML instance is located.
Public property XmlSchemaCollectionName Gets the name of the schema collection for this XML instance.
Public property XmlSchemaCollectionOwningSchema Gets the owning relational schema where the schema collection for this XML instance is located.
Top
  Name Description
Public method Adjust(Boolean) Validates the specified Boolean value against the metadata, and adjusts the value if necessary.
Public method Adjust(Byte) Validates the specified Byte value against the metadata, and adjusts the value if necessary.
Public method Adjust(Byte[]) Validates the specified array of Byte values against the metadata, and adjusts the value if necessary.
Public method Adjust(Char) Validates the specified Char value against the metadata, and adjusts the value if necessary.
Public method Adjust(Char[]) Validates the specified array of Char values against the metadata, and adjusts the value if necessary.
Public method Adjust(DateTime) Validates the specified DateTime value against the metadata, and adjusts the value if necessary.
Public method Adjust(DateTimeOffset) Validates the specified DateTimeOffset value against the metadata, and adjusts the value if necessary.
Public method Adjust(Decimal) Validates the specified Decimal value against the metadata, and adjusts the value if necessary.
Public method Adjust(Double) Validates the specified Double value against the metadata, and adjusts the value if necessary.
Public method Adjust(Guid) Validates the specified Guid value against the metadata, and adjusts the value if necessary.
Public method Adjust(Int16) Validates the specified Int16 value against the metadata, and adjusts the value if necessary.
Public method Adjust(Int32) Validates the specified Int32 value against the metadata, and adjusts the value if necessary.
Public method Adjust(Int64) Validates the specified Int64 value against the metadata, and adjusts the value if necessary.
Public method Adjust(Object) Validates the specified Object value against the metadata, and adjusts the value if necessary.
Public method Adjust(Single) Validates the specified Single value against the metadata, and adjusts the value if necessary.
Public method Adjust(SqlBinary) Validates the specified SqlBinary value against the metadata, and adjusts the value if necessary.
Public method Adjust(SqlBoolean) Validates the specified SqlBoolean value against the metadata, and adjusts the value if necessary.
Public method Adjust(SqlByte) Validates the specified SqlByte value against the metadata, and adjusts the value if necessary.
Public method Adjust(SqlBytes) Validates the specified SqlBytes value against the metadata, and adjusts the value if necessary.
Public method Adjust(SqlChars) Validates the specified SqlChars value against the metadata, and adjusts the value if necessary.
Public method Adjust(SqlDateTime) Validates the specified SqlDateTime value against the metadata, and adjusts the value if necessary.
Public method Adjust(SqlDecimal) Validates the specified SqlDecimal value against the metadata, and adjusts the value if necessary.
Public method Adjust(SqlDouble) Validates the specified SqlDouble value against the metadata, and adjusts the value if necessary.
Public method Adjust(SqlGuid) Validates the specified SqlGuid value against the metadata, and adjusts the value if necessary.
Public method Adjust(SqlInt16) Validates the specified SqlInt16 value against the metadata, and adjusts the value if necessary.
Public method Adjust(SqlInt32) Validates the specified SqlInt32 value against the metadata, and adjusts the value if necessary.
Public method Adjust(SqlInt64) Validates the specified SqlInt64 value against the metadata, and adjusts the value if necessary.
Public method Adjust(SqlMoney) Validates the specified SqlMoney value against the metadata, and adjusts the value if necessary.
Public method Adjust(SqlSingle) Validates the specified SqlSingle value against the metadata, and adjusts the value if necessary.
Public method Adjust(SqlString) Validates the specified SqlString value against the metadata, and adjusts the value if necessary.
Public method Adjust(SqlXml) Validates the specified SqlXml value against the metadata, and adjusts the value if necessary.
Public method Adjust(String) Validates the specified String value against the metadata, and adjusts the value if necessary.
Public method Adjust(TimeSpan) Validates the specified TimeSpan value against the metadata, and adjusts the value if necessary.
Public method Equals(Object) Determines whether the specified Object is equal to the current Object. (Inherited from Object.)
Protected method Finalize Allows an object to try to free resources and perform other cleanup operations before it is reclaimed by garbage collection. (Inherited from Object.)
Public method GetHashCode Serves as a hash function for a particular type. (Inherited from Object.)
Public method GetType Gets the Type of the current instance. (Inherited from Object.)
Public method Static member InferFromValue Infers the metadata from the specified object and returns it as a SqlMetaData instance.
Protected method MemberwiseClone Creates a shallow copy of the current Object. (Inherited from Object.)
Public method ToString Returns 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 static void CreateNewRecord()
{
   // Variables.
   SqlMetaData column1Info;
   SqlMetaData column2Info;
   SqlMetaData column3Info;
   SqlDataRecord record;

   // 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);
}


.NET Framework

Supported in: 4, 3.5, 3.0, 2.0

.NET Framework Client Profile

Supported in: 4, 3.5 SP1

Windows 7, Windows Vista SP1 or later, Windows XP SP3, Windows XP SP2 x64 Edition, Windows Server 2008 (Server Core not supported), Windows Server 2008 R2 (Server Core supported with SP1 or later), Windows Server 2003 SP2

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)
Community Content Add
Annotations FAQ