Export (0) Print
Expand All

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.

  NameDescription
Public methodSqlDataRecordInititializes a new SqlDataRecord instance with the schema based on the array of SqlMetaData objects passed as an argument.
Top

  NameDescription
Public propertyFieldCountGets the number of columns in the data row. This property is read-only.
Public propertyItem[Int32]Gets the common language runtime (CLR) type value for the column specified by the column ordinal argument.
Public propertyItem[String]Gets the common language runtime (CLR) type value for the column specified by the column name argument.
Top

  NameDescription
Public methodEquals(Object)Determines whether the specified object is equal to the current object. (Inherited from Object.)
Protected methodFinalizeAllows an object to try to free resources and perform other cleanup operations before it is reclaimed by garbage collection. (Inherited from Object.)
Public methodGetBooleanGets the value for the column specified by the ordinal as a Boolean.
Public methodGetByteGets the value for the column specified by the ordinal as a Byte.
Public methodGetBytesGets the value for the column specified by the ordinal as an array of Byte objects.
Public methodGetCharGets the value for the column specified by the ordinal as a Char.
Public methodGetCharsGets the value for the column specified by the ordinal as an array of Char objects.
Public methodGetDataTypeNameReturns the name of the data type for the column specified by the ordinal argument.
Public methodGetDateTimeGets the value for the column specified by the ordinal as a DateTime.
Public methodGetDateTimeOffsetReturns the specified column’s data as a DateTimeOffset.
Public methodGetDecimalGets the value for the column specified by the ordinal as a Decimal.
Public methodGetDoubleGets the value for the column specified by the ordinal as a Double.
Public methodGetFieldTypeReturns 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 methodGetFloatGets the value for the column specified by the ordinal as a float.
Public methodGetGuidGets the value for the column specified by the ordinal as a Guid.
Public methodGetHashCodeServes as the default hash function. (Inherited from Object.)
Public methodGetInt16Gets the value for the column specified by the ordinal as a Int16.
Public methodGetInt32Gets the value for the column specified by the ordinal as a Int32.
Public methodGetInt64Gets the value for the column specified by the ordinal as a Int64.
Public methodGetNameReturns the name of the column specified by the ordinal argument.
Public methodGetOrdinalReturns the column ordinal specified by the column name.
Public methodGetSqlBinaryGets the value for the column specified by the ordinal as a SqlBinary.
Public methodGetSqlBooleanGets the value for the column specified by the ordinal as a SqlBoolean.
Public methodGetSqlByteGets the value for the column specified by the ordinal as a SqlByte.
Public methodGetSqlBytesGets the value for the column specified by the ordinal as a SqlBytes.
Public methodGetSqlCharsGets the value for the column specified by the ordinal as a SqlChars.
Public methodGetSqlDateTimeGets the value for the column specified by the ordinal as a SqlDateTime.
Public methodGetSqlDecimalGets the value for the column specified by the ordinal as a SqlDecimal.
Public methodGetSqlDoubleGets the value for the column specified by the ordinal as a SqlDouble.
Public methodGetSqlFieldTypeReturns 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 methodGetSqlGuidGets the value for the column specified by the ordinal as a SqlGuid.
Public methodGetSqlInt16Gets the value for the column specified by the ordinal as a SqlInt16.
Public methodGetSqlInt32Gets the value for the column specified by the ordinal as a SqlInt32.
Public methodGetSqlInt64Gets the value for the column specified by the ordinal as a SqlInt64.
Public methodGetSqlMetaDataReturns a SqlMetaData object, describing the metadata of the column specified by the column ordinal.
Public methodGetSqlMoneyGets the value for the column specified by the ordinal as a SqlMoney.
Public methodGetSqlSingleGets the value for the column specified by the ordinal as a SqlSingle.
Public methodGetSqlStringGets the value for the column specified by the ordinal as a SqlString.
Public methodGetSqlValueReturns the data value stored in the column, expressed as a SQL Server type, specified by the column ordinal.
Public methodGetSqlValuesReturns the values for all the columns in the record, expressed as SQL Server types, in an array.
Public methodGetSqlXmlGets the value for the column specified by the ordinal as a SqlXml.
Public methodGetStringGets the value for the column specified by the ordinal as a String.
Public methodGetTimeSpanReturns the specified column’s data as a TimeSpan.
Public methodGetTypeGets the Type of the current instance. (Inherited from Object.)
Public methodGetValueReturns the common language runtime (CLR) type value for the column specified by the ordinal argument.
Public methodGetValuesReturns the values for all the columns in the record, expressed as common language runtime (CLR) types, in an array.
Public methodIsDBNullReturns true if the column specified by the column ordinal parameter is null.
Protected methodMemberwiseCloneCreates a shallow copy of the current Object. (Inherited from Object.)
Public methodSetBooleanSets the data stored in the column to the specified Boolean value.
Public methodSetByteSets the data stored in the column to the specified Byte value.
Public methodSetBytesSets the data stored in the column to the specified array of Byte values.
Public methodSetCharSets the data stored in the column to the specified Char value.
Public methodSetCharsSets the data stored in the column to the specified array of Char values.
Public methodSetDateTimeSets the data stored in the column to the specified DateTime value.
Public methodSetDateTimeOffsetSets the value of the column specified to the DateTimeOffset value.
Public methodSetDBNullSets the value in the specified column to DBNull.
Public methodSetDecimalSets the data stored in the column to the specified Decimal value.
Public methodSetDoubleSets the data stored in the column to the specified Double value.
Public methodSetFloatSets the data stored in the column to the specified float value.
Public methodSetGuidSets the data stored in the column to the specified Guid value.
Public methodSetInt16Sets the data stored in the column to the specified Int16 value.
Public methodSetInt32Sets the data stored in the column to the specified Int32 value.
Public methodSetInt64Sets the data stored in the column to the specified Int64 value.
Public methodSetSqlBinarySets the data stored in the column to the specified SqlBinary value.
Public methodSetSqlBooleanSets the data stored in the column to the specified SqlBoolean value.
Public methodSetSqlByteSets the data stored in the column to the specified SqlByte value.
Public methodSetSqlBytesSets the data stored in the column to the specified SqlBytes value.
Public methodSetSqlCharsSets the data stored in the column to the specified SqlChars value.
Public methodSetSqlDateTimeSets the data stored in the column to the specified SqlDateTime value.
Public methodSetSqlDecimalSets the data stored in the column to the specified SqlDecimal value.
Public methodSetSqlDoubleSets the data stored in the column to the specified SqlDouble value.
Public methodSetSqlGuidSets the data stored in the column to the specified SqlGuid value.
Public methodSetSqlInt16Sets the data stored in the column to the specified SqlInt16 value.
Public methodSetSqlInt32Sets the data stored in the column to the specified SqlInt32 value.
Public methodSetSqlInt64Sets the data stored in the column to the specified SqlInt64 value.
Public methodSetSqlMoneySets the data stored in the column to the specified SqlMoney value.
Public methodSetSqlSingleSets the data stored in the column to the specified SqlSingle value.
Public methodSetSqlStringSets the data stored in the column to the specified SqlString value.
Public methodSetSqlXmlSets the data stored in the column to the specified SqlXml value.
Public methodSetStringSets the data stored in the column to the specified String value.
Public methodSetTimeSpanSets the value of the column specified to the TimeSpan.
Public methodSetValueSets a new value, expressed as a common language runtime (CLR) type, for the column specified by the column ordinal.
Public methodSetValuesSets new values for all of the columns in the SqlDataRecord. These values are expressed as common language runtime (CLR) types.
Public methodToStringReturns a string that represents the current object. (Inherited from Object.)
Top

  NameDescription
Explicit interface implemetationPrivate methodIDataRecord.GetDataNot 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.5, 4, 3.5, 3.0, 2.0

.NET Framework Client Profile

Supported in: 4, 3.5 SP1

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.
Show:
© 2014 Microsoft