This topic has not yet been rated - Rate this topic

SqlDataRecord Class

Represents a single row of data and its metadata. This class cannot be inherited.

System.Object
  Microsoft.SqlServer.Server.SqlDataRecord

Namespace:  Microsoft.SqlServer.Server
Assembly:  System.Data (in System.Data.dll)
public class SqlDataRecord : IDataRecord

The SqlDataRecord type exposes the following members.

  Name Description
Public method SqlDataRecord Inititializes a new SqlDataRecord instance with the schema based on the array of SqlMetaData objects passed as an argument.
Top
  Name Description
Public property FieldCount Gets the number of columns in the data row. This property is read-only.
Public property Item[Int32] Gets the common language runtime (CLR) type value for the column specified by the column ordinal argument.
Public property Item[String] Gets the common language runtime (CLR) type value for the column specified by the column name argument.
Top
  Name Description
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 GetBoolean Gets the value for the column specified by the ordinal as a Boolean.
Public method GetByte Gets the value for the column specified by the ordinal as a Byte.
Public method GetBytes Gets the value for the column specified by the ordinal as an array of Byte objects.
Public method GetChar Gets the value for the column specified by the ordinal as a Char.
Public method GetChars Gets the value for the column specified by the ordinal as an array of Char objects.
Public method GetDataTypeName Returns the name of the data type for the column specified by the ordinal argument.
Public method GetDateTime Gets the value for the column specified by the ordinal as a DateTime.
Public method GetDateTimeOffset Returns the specified column’s data as a DateTimeOffset.
Public method GetDecimal Gets the value for the column specified by the ordinal as a Decimal.
Public method GetDouble Gets the value for the column specified by the ordinal as a Double.
Public method GetFieldType Returns a Type object representing the common language runtime (CLR) type that maps to the SQL Server type of the column specified by the ordinal argument.
Public method GetFloat Gets the value for the column specified by the ordinal as a float.
Public method GetGuid Gets the value for the column specified by the ordinal as a Guid.
Public method GetHashCode Serves as a hash function for a particular type. (Inherited from Object.)
Public method GetInt16 Gets the value for the column specified by the ordinal as a Int16.
Public method GetInt32 Gets the value for the column specified by the ordinal as a Int32.
Public method GetInt64 Gets the value for the column specified by the ordinal as a Int64.
Public method GetName Returns the name of the column specified by the ordinal argument.
Public method GetOrdinal Returns the column ordinal specified by the column name.
Public method GetSqlBinary Gets the value for the column specified by the ordinal as a SqlBinary.
Public method GetSqlBoolean Gets the value for the column specified by the ordinal as a SqlBoolean.
Public method GetSqlByte Gets the value for the column specified by the ordinal as a SqlByte.
Public method GetSqlBytes Gets the value for the column specified by the ordinal as a SqlBytes.
Public method GetSqlChars Gets the value for the column specified by the ordinal as a SqlChars.
Public method GetSqlDateTime Gets the value for the column specified by the ordinal as a SqlDateTime.
Public method GetSqlDecimal Gets the value for the column specified by the ordinal as a SqlDecimal.
Public method GetSqlDouble Gets the value for the column specified by the ordinal as a SqlDouble.
Public method GetSqlFieldType Returns a Type object that represents the type (as a SQL Server type, defined in System.Data.SqlTypes) that maps to the SQL Server type of the column.
Public method GetSqlGuid Gets the value for the column specified by the ordinal as a SqlGuid.
Public method GetSqlInt16 Gets the value for the column specified by the ordinal as a SqlInt16.
Public method GetSqlInt32 Gets the value for the column specified by the ordinal as a SqlInt32.
Public method GetSqlInt64 Gets the value for the column specified by the ordinal as a SqlInt64.
Public method GetSqlMetaData Returns a SqlMetaData object, describing the metadata of the column specified by the column ordinal.
Public method GetSqlMoney Gets the value for the column specified by the ordinal as a SqlMoney.
Public method GetSqlSingle Gets the value for the column specified by the ordinal as a SqlSingle.
Public method GetSqlString Gets the value for the column specified by the ordinal as a SqlString.
Public method GetSqlValue Returns the data value stored in the column, expressed as a SQL Server type, specified by the column ordinal.
Public method GetSqlValues Returns the values for all the columns in the record, expressed as SQL Server types, in an array.
Public method GetSqlXml Gets the value for the column specified by the ordinal as a SqlXml.
Public method GetString Gets the value for the column specified by the ordinal as a String.
Public method GetTimeSpan Returns the specified column’s data as a TimeSpan.
Public method GetType Gets the Type of the current instance. (Inherited from Object.)
Public method GetValue Returns the common language runtime (CLR) type value for the column specified by the ordinal argument.
Public method GetValues Returns the values for all the columns in the record, expressed as common language runtime (CLR) types, in an array.
Public method IsDBNull Returns true if the column specified by the column ordinal parameter is null.
Protected method MemberwiseClone Creates a shallow copy of the current Object. (Inherited from Object.)
Public method SetBoolean Sets the data stored in the column to the specified Boolean value.
Public method SetByte Sets the data stored in the column to the specified Byte value.
Public method SetBytes Sets the data stored in the column to the specified array of Byte values.
Public method SetChar Sets the data stored in the column to the specified Char value.
Public method SetChars Sets the data stored in the column to the specified array of Char values.
Public method SetDateTime Sets the data stored in the column to the specified DateTime value.
Public method SetDateTimeOffset Sets the value of the column specified to the DateTimeOffset value.
Public method SetDBNull Sets the value in the specified column to DBNull.
Public method SetDecimal Sets the data stored in the column to the specified Decimal value.
Public method SetDouble Sets the data stored in the column to the specified Double value.
Public method SetFloat Sets the data stored in the column to the specified float value.
Public method SetGuid Sets the data stored in the column to the specified Guid value.
Public method SetInt16 Sets the data stored in the column to the specified Int16 value.
Public method SetInt32 Sets the data stored in the column to the specified Int32 value.
Public method SetInt64 Sets the data stored in the column to the specified Int64 value.
Public method SetSqlBinary Sets the data stored in the column to the specified SqlBinary value.
Public method SetSqlBoolean Sets the data stored in the column to the specified SqlBoolean value.
Public method SetSqlByte Sets the data stored in the column to the specified SqlByte value.
Public method SetSqlBytes Sets the data stored in the column to the specified SqlBytes value.
Public method SetSqlChars Sets the data stored in the column to the specified SqlChars value.
Public method SetSqlDateTime Sets the data stored in the column to the specified SqlDateTime value.
Public method SetSqlDecimal Sets the data stored in the column to the specified SqlDecimal value.
Public method SetSqlDouble Sets the data stored in the column to the specified SqlDouble value.
Public method SetSqlGuid Sets the data stored in the column to the specified SqlGuid value.
Public method SetSqlInt16 Sets the data stored in the column to the specified SqlInt16 value.
Public method SetSqlInt32 Sets the data stored in the column to the specified SqlInt32 value.
Public method SetSqlInt64 Sets the data stored in the column to the specified SqlInt64 value.
Public method SetSqlMoney Sets the data stored in the column to the specified SqlMoney value.
Public method SetSqlSingle Sets the data stored in the column to the specified SqlSingle value.
Public method SetSqlString Sets the data stored in the column to the specified SqlString value.
Public method SetSqlXml Sets the data stored in the column to the specified SqlXml value.
Public method SetString Sets the data stored in the column to the specified String value.
Public method SetTimeSpan Sets the value of the column specified to the TimeSpan.
Public method SetValue Sets a new value, expressed as a common language runtime (CLR) type, for the column specified by the column ordinal.
Public method SetValues Sets new values for all of the columns in the SqlDataRecord. These values are expressed as common language runtime (CLR) types.
Public method ToString Returns a string that represents the current object. (Inherited from Object.)
Top
  Name Description
Explicit interface implemetation Private method IDataRecord.GetData Not supported in this release.
Top

This class is used together with SqlPipe to send result sets to the client from managed code stored-procedures.

When writing common language runtime (CLR) applications, you should re-use existing SqlDataRecord objects instead of creating new ones every time. Creating many new SqlDataRecord objects could severely deplete memory and adversely affect performance.

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


[Microsoft.SqlServer.Server.SqlProcedure]
public static void CreateNewRecord()
{

   // Variables.
   SqlDataRecord record;    

   // Create a new record with the column metadata. The constructor is 
   // able to accept a variable number of parameters. 
   record = new SqlDataRecord(new SqlMetaData[] { new SqlMetaData("Column1", SqlDbType.NVarChar, 12), 
                                                  new SqlMetaData("Column2", SqlDbType.Int), 
                                                  new SqlMetaData("Column3", SqlDbType.DateTime) });

   // 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