Note
Access to this page requires authorization. You can try signing in or .
Access to this page requires authorization. You can try .
SqlDataRecord Class
Definition
- Namespace:
- Microsoft.SqlServer.Server
- Assembly:
- System.Data.SqlClient.dll
- Assembly:
- System.Data.dll
- Package:
- System.Data.SqlClient v4.8.5
- Source:
- SqlDataRecord.cs
Important
Some information relates to prerelease product that may be substantially modified before it’s released. Microsoft makes no warranties, express or implied, with respect to the information provided here.
Represents a single row of data and its metadata. This class cannot be inherited.
public ref class SqlDataRecord : System::Data::IDataRecord
public class SqlDataRecord : System.Data.IDataRecord
type SqlDataRecord = class
interface IDataRecord
Public Class SqlDataRecord
Implements IDataRecord
- Inheritance
-
SqlDataRecord
- Implements
Examples
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);
}
<Microsoft.SqlServer.Server.SqlProcedure()> _
Public Shared Sub CreateNewRecord()
' Variables.
Dim record As SqlDataRecord
' 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)
End Sub
Remarks
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.
Constructors
| Name | Description |
|---|---|
| SqlDataRecord(SqlMetaData[]) |
Inititializes a new SqlDataRecord instance with the schema based on the array of SqlMetaData objects passed as an argument. |
Properties
| Name | Description |
|---|---|
| FieldCount |
Gets the number of columns in the data row. This property is read-only. |
| Item[Int32] |
Gets the common language runtime (CLR) type value for the column specified by the column |
| Item[String] |
Gets the common language runtime (CLR) type value for the column specified by the column |
Methods
| Name | Description |
|---|---|
| GetBoolean(Int32) |
Gets the value for the column specified by the ordinal as a Boolean. |
| GetByte(Int32) |
Gets the value for the column specified by the ordinal as a Byte. |
| GetBytes(Int32, Int64, Byte[], Int32, Int32) |
Gets the value for the column specified by the ordinal as an array of Byte objects. |
| GetChar(Int32) |
Gets the value for the column specified by the ordinal as a Char. |
| GetChars(Int32, Int64, Char[], Int32, Int32) |
Gets the value for the column specified by the ordinal as an array of Char objects. |
| GetDataTypeName(Int32) |
Returns the name of the data type for the column specified by the ordinal argument. |
| GetDateTime(Int32) |
Gets the value for the column specified by the ordinal as a DateTime. |
| GetDateTimeOffset(Int32) |
Returns the specified column's data as a DateTimeOffset. |
| GetDecimal(Int32) |
Gets the value for the column specified by the ordinal as a Decimal. |
| GetDouble(Int32) |
Gets the value for the column specified by the ordinal as a Double. |
| GetFieldType(Int32) |
Returns a Type object representing the common language runtime (CLR) type that maps to the SQL Server type of the column specified by the |
| GetFloat(Int32) |
Gets the value for the column specified by the ordinal as a |
| GetGuid(Int32) |
Gets the value for the column specified by the ordinal as a Guid. |
| GetInt16(Int32) |
Gets the value for the column specified by the ordinal as a Int16. |
| GetInt32(Int32) |
Gets the value for the column specified by the ordinal as a Int32. |
| GetInt64(Int32) |
Gets the value for the column specified by the ordinal as a Int64. |
| GetName(Int32) |
Returns the name of the column specified by the ordinal argument. |
| GetOrdinal(String) |
Returns the column ordinal specified by the column name. |
| GetSqlBinary(Int32) |
Gets the value for the column specified by the ordinal as a SqlBinary. |
| GetSqlBoolean(Int32) |
Gets the value for the column specified by the ordinal as a SqlBoolean. |
| GetSqlByte(Int32) |
Gets the value for the column specified by the ordinal as a SqlByte. |
| GetSqlBytes(Int32) |
Gets the value for the column specified by the ordinal as a SqlBytes. |
| GetSqlChars(Int32) |
Gets the value for the column specified by the ordinal as a SqlChars. |
| GetSqlDateTime(Int32) |
Gets the value for the column specified by the ordinal as a SqlDateTime. |
| GetSqlDecimal(Int32) |
Gets the value for the column specified by the ordinal as a SqlDecimal. |
| GetSqlDouble(Int32) |
Gets the value for the column specified by the ordinal as a SqlDouble. |
| GetSqlFieldType(Int32) |
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. |
| GetSqlGuid(Int32) |
Gets the value for the column specified by the ordinal as a SqlGuid. |
| GetSqlInt16(Int32) |
Gets the value for the column specified by the ordinal as a SqlInt16. |
| GetSqlInt32(Int32) |
Gets the value for the column specified by the ordinal as a SqlInt32. |
| GetSqlInt64(Int32) |
Gets the value for the column specified by the ordinal as a SqlInt64. |
| GetSqlMetaData(Int32) |
Returns a SqlMetaData object, describing the metadata of the column specified by the column ordinal. |
| GetSqlMoney(Int32) |
Gets the value for the column specified by the ordinal as a SqlMoney. |
| GetSqlSingle(Int32) |
Gets the value for the column specified by the ordinal as a SqlSingle. |
| GetSqlString(Int32) |
Gets the value for the column specified by the ordinal as a SqlString. |
| GetSqlValue(Int32) |
Returns the data value stored in the column, expressed as a SQL Server type, specified by the column ordinal. |
| GetSqlValues(Object[]) |
Returns the values for all the columns in the record, expressed as SQL Server types, in an array. |
| GetSqlXml(Int32) |
Gets the value for the column specified by the ordinal as a SqlXml. |
| GetString(Int32) |
Gets the value for the column specified by the ordinal as a String. |
| GetTimeSpan(Int32) |
Returns the specified column's data as a TimeSpan. |
| GetValue(Int32) |
Returns the common language runtime (CLR) type value for the column specified by the ordinal argument. |
| GetValues(Object[]) |
Returns the values for all the columns in the record, expressed as common language runtime (CLR) types, in an array. |
| IsDBNull(Int32) |
Returns true if the column specified by the column ordinal parameter is null. |
| SetBoolean(Int32, Boolean) |
Sets the data stored in the column to the specified Boolean value. |
| SetByte(Int32, Byte) |
Sets the data stored in the column to the specified Byte value. |
| SetBytes(Int32, Int64, Byte[], Int32, Int32) |
Sets the data stored in the column to the specified array of Byte values. |
| SetChar(Int32, Char) |
Sets the data stored in the column to the specified Char value. |
| SetChars(Int32, Int64, Char[], Int32, Int32) |
Sets the data stored in the column to the specified array of Char values. |
| SetDateTime(Int32, DateTime) |
Sets the data stored in the column to the specified DateTime value. |
| SetDateTimeOffset(Int32, DateTimeOffset) |
Sets the value of the column specified to the DateTimeOffset value. |
| SetDBNull(Int32) |
Sets the value in the specified column to DBNull. |
| SetDecimal(Int32, Decimal) |
Sets the data stored in the column to the specified Decimal value. |
| SetDouble(Int32, Double) |
Sets the data stored in the column to the specified Double value. |
| SetFloat(Int32, Single) |
Sets the data stored in the column to the specified |
| SetGuid(Int32, Guid) |
Sets the data stored in the column to the specified Guid value. |
| SetInt16(Int32, Int16) |
Sets the data stored in the column to the specified Int16 value. |
| SetInt32(Int32, Int32) |
Sets the data stored in the column to the specified Int32 value. |
| SetInt64(Int32, Int64) |
Sets the data stored in the column to the specified Int64 value. |
| SetSqlBinary(Int32, SqlBinary) |
Sets the data stored in the column to the specified SqlBinary value. |
| SetSqlBoolean(Int32, SqlBoolean) |
Sets the data stored in the column to the specified SqlBoolean value. |
| SetSqlByte(Int32, SqlByte) |
Sets the data stored in the column to the specified SqlByte value. |
| SetSqlBytes(Int32, SqlBytes) |
Sets the data stored in the column to the specified SqlBytes value. |
| SetSqlChars(Int32, SqlChars) |
Sets the data stored in the column to the specified SqlChars value. |
| SetSqlDateTime(Int32, SqlDateTime) |
Sets the data stored in the column to the specified SqlDateTime value. |
| SetSqlDecimal(Int32, SqlDecimal) |
Sets the data stored in the column to the specified SqlDecimal value. |
| SetSqlDouble(Int32, SqlDouble) |
Sets the data stored in the column to the specified SqlDouble value. |
| SetSqlGuid(Int32, SqlGuid) |
Sets the data stored in the column to the specified SqlGuid value. |
| SetSqlInt16(Int32, SqlInt16) |
Sets the data stored in the column to the specified SqlInt16 value. |
| SetSqlInt32(Int32, SqlInt32) |
Sets the data stored in the column to the specified SqlInt32 value. |
| SetSqlInt64(Int32, SqlInt64) |
Sets the data stored in the column to the specified SqlInt64 value. |
| SetSqlMoney(Int32, SqlMoney) |
Sets the data stored in the column to the specified SqlMoney value. |
| SetSqlSingle(Int32, SqlSingle) |
Sets the data stored in the column to the specified SqlSingle value. |
| SetSqlString(Int32, SqlString) |
Sets the data stored in the column to the specified SqlString value. |
| SetSqlXml(Int32, SqlXml) |
Sets the data stored in the column to the specified SqlXml value. |
| SetString(Int32, String) |
Sets the data stored in the column to the specified String value. |
| SetTimeSpan(Int32, TimeSpan) |
Sets the value of the column specified to the TimeSpan. |
| SetValue(Int32, Object) |
Sets a new value, expressed as a common language runtime (CLR) type, for the column specified by the column ordinal. |
| SetValues(Object[]) |
Sets new values for all of the columns in the SqlDataRecord. These values are expressed as common language runtime (CLR) types. |
Explicit Interface Implementations
| Name | Description |
|---|---|
| IDataRecord.GetData(Int32) |
Not supported in this release. |
