.NET Framework Class Library IDataRecord Interface Provides access to the column values within each row for a DataReader, and is implemented by .NET Framework data providers that access relational databases.
Namespace:
System.Data
Assembly:
System.Data (in System.Data.dll)

Syntax
Public Interface IDataRecord
public interface IDataRecord
public interface class IDataRecord
type IDataRecord = interface end
The IDataRecord type exposes the following members.

Properties

Remarks
The IDataReader and IDataRecord interfaces enable an inheriting class to implement a DataReader class. This provides a way of reading one or more forward-only streams of result sets. For more information about DataReader classes, see Retrieving Data Using a DataReader (ADO.NET). An application does not create an instance of the IDataRecord interface directly, but creates an instance of a class that inherits IDataRecord. Typically, you do this by obtaining a DataReader through the ExecuteReader method of the Command object. Classes that inherit IDataRecord must implement all inherited members, and typically define additional members to add provider-specific functionality. Providers implementing a DataReader are required to expose data in common language runtime (CLR) types. Type coercion is defined for some types not included in the CLR. These values may be accessed as alternative types that comply with CLR types. As an example, the following table lists suggested mappings from OLE DB data types to CLR types, with alternative types in parentheses. OLE DB type | CLR type |
|---|
DBTYPE_BOOL | Int16 | DBTYPE_BSTR | string | DBTYPE_BYTES | byte[] | DBTYPE_CY | Decimal | DBTYPE_DATE | DateTime | DBTYPE_DBDATE | DateTime | DBTYPE_DBTIME | DateTime | DBTYPE_DBTIMESTAMP | DateTime | DBTYPE_DECIMAL | Decimal | DBTYPE_EMPTY | null | DBTYPE_ERROR | ExternalException | DBTYPE_FILETIME | DateTime | DBTYPE_GUID | Guid | DBTYPE_HCHAPTER | not supported | DBTYPE_I1 | SByte | DBTYPE_I2 | Int16 | DBTYPE_I4 | Int32 | DBTYPE_I8 | Int64 | DBTYPE_IDISPATCH | object | DBTYPE_IUNKNOWN | object | DBTYPE_NULL | DBNull.Value | DBTYPE_NUMERIC | Decimal | DBTYPE_PROPVARIANT | object | DBTYPE_R4 | Single | DBTYPE_R8 | Double | DBTYPE_STR | string | DBTYPE_UDT | not supported | DBTYPE_UI1 | byte (Int16) | DBTYPE_UI2 | UInt16 (Int32) | DBTYPE_UI4 | UInt32 (Int64) | DBTYPE_UI8 | UInt64 (Decimal) | DBTYPE_VARIANT | object | DBTYPE_VARNUMERIC | not supported | DBTYPE_WSTR | string |

Examples
The following example creates instances of the derived classes, SqlConnection, SqlCommand, and SqlDataReader. The example reads through the data, writing it out to the console. Finally, the example closes the SqlDataReader, and then the SqlConnection.
Private Sub ReadOrderData(ByVal connectionString As String)
Dim queryString As String = _
"SELECT OrderID, CustomerID FROM dbo.Orders;"
Using connection As New SqlConnection(connectionString)
Dim command As New SqlCommand(queryString, connection)
connection.Open()
Dim reader As SqlDataReader = command.ExecuteReader()
' Call Read before accessing data.
While reader.Read()
Console.WriteLine(String.Format("{0}, {1}", _
reader(0), reader(1)))
End While
' Call Close when done reading.
reader.Close()
End Using
End Sub
private static void ReadOrderData(string connectionString)
{
string queryString =
"SELECT OrderID, CustomerID FROM dbo.Orders;";
using (SqlConnection connection =
new SqlConnection(connectionString))
{
SqlCommand command =
new SqlCommand(queryString, connection);
connection.Open();
SqlDataReader reader = command.ExecuteReader();
// Call Read before accessing data.
while (reader.Read())
{
Console.WriteLine(String.Format("{0}, {1}",
reader[0], reader[1]));
}
// Call Close when done reading.
reader.Close();
}
}

Version Information
.NET FrameworkSupported in: 4, 3.5, 3.0, 2.0, 1.1, 1.0 .NET Framework Client ProfileSupported in: 4, 3.5 SP1

Platforms
Windows 7, Windows Vista SP1 or later, Windows XP SP3, Windows XP SP2 x64 Edition, Windows Server 2008 (Server Core Role not supported), Windows Server 2008 R2 (Server Core Role not supported), 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.

See Also
|
Biblioteca de clases de .NET Framework IDataRecord (Interfaz) Proporciona acceso a los valores de columna de cada fila para un DataReader. La implementan los proveedores de datos de .NET Framework que tienen acceso a bases de datos relacionales.
Espacio de nombres:
System.Data
Ensamblado:
System.Data (en System.Data.dll)

Sintaxis
Public Interface IDataRecord
public interface IDataRecord
public interface class IDataRecord
type IDataRecord = interface end
El tipo IDataRecord expone los siguientes miembros.

Propiedades

Comentarios
Las interfaces IDataReader y IDataRecord permiten que una clase heredera implemente una clase DataReader. Esto proporciona una manera de leer una o varias secuencias de tipo sólo hacia delante de los conjuntos de resultados. Para obtener más información sobre las clases DataReader, vea Recuperar datos mediante DataReader (ADO.NET). Una aplicación no crea una instancia de la interfaz IDataRecord directamente, sino que crea una instancia de una clase que hereda de IDataRecord. Normalmente, esto se realiza obteniendo un objeto DataReader mediante el método ExecuteReader del objeto Command. Las clases que heredan IDataRecord deben implementar todos los miembros heredados y suelen definir miembros adicionales para agregar la funcionalidad específica de proveedor. Los proveedores que implementan un objeto DataReader son necesarios para exponer datos en tipos de Common Language Runtime (CLR). La conversión de tipos se define para algunos tipos no incluidos en CLR. Se puede obtener acceso a estos valores como tipos alternativos que siguen los tipos CLR. Como ejemplo, en la tabla siguiente se enumeran asignaciones sugeridas de tipos de datos OLE DB a tipos CLR, con tipos alternativos entre paréntesis. Tipo OLE DB | Tipo CLR |
|---|
DBTYPE_BOOL | Int16 | DBTYPE_BSTR | string | DBTYPE_BYTES | byte[] | DBTYPE_CY | Decimal | DBTYPE_DATE | DateTime | DBTYPE_DBDATE | DateTime | DBTYPE_DBTIME | DateTime | DBTYPE_DBTIMESTAMP | DateTime | DBTYPE_DECIMAL | Decimal | DBTYPE_EMPTY | null | DBTYPE_ERROR | ExternalException | DBTYPE_FILETIME | DateTime | DBTYPE_GUID | Guid | DBTYPE_HCHAPTER | no admitido | DBTYPE_I1 | SByte | DBTYPE_I2 | Int16 | DBTYPE_I4 | Int32 | DBTYPE_I8 | Int64 | DBTYPE_IDISPATCH | objeto | DBTYPE_IUNKNOWN | objeto | DBTYPE_NULL | DBNull.Value | DBTYPE_NUMERIC | Decimal | DBTYPE_PROPVARIANT | objeto | DBTYPE_R4 | Simple | DBTYPE_R8 | Double | DBTYPE_STR | string | DBTYPE_UDT | no admitido | DBTYPE_UI1 | byte (Int16) | DBTYPE_UI2 | UInt16 (Int32) | DBTYPE_UI4 | UInt32 (Int64) | DBTYPE_UI8 | UInt64 (Decimal) | DBTYPE_VARIANT | objeto | DBTYPE_VARNUMERIC | no admitido | DBTYPE_WSTR | string |

Ejemplos
En el ejemplo siguiente se crean instancias de las clases derivadas SqlConnection, SqlCommand y SqlDataReader. En el ejemplo se leen los datos y se escriben en la consola. Por último, en el ejemplo se cierra el objeto SqlDataReader y, a continuación, el objeto SqlConnection.
Private Sub ReadOrderData(ByVal connectionString As String)
Dim queryString As String = _
"SELECT OrderID, CustomerID FROM dbo.Orders;"
Using connection As New SqlConnection(connectionString)
Dim command As New SqlCommand(queryString, connection)
connection.Open()
Dim reader As SqlDataReader = command.ExecuteReader()
' Call Read before accessing data.
While reader.Read()
Console.WriteLine(String.Format("{0}, {1}", _
reader(0), reader(1)))
End While
' Call Close when done reading.
reader.Close()
End Using
End Sub
private static void ReadOrderData(string connectionString)
{
string queryString =
"SELECT OrderID, CustomerID FROM dbo.Orders;";
using (SqlConnection connection =
new SqlConnection(connectionString))
{
SqlCommand command =
new SqlCommand(queryString, connection);
connection.Open();
SqlDataReader reader = command.ExecuteReader();
// Call Read before accessing data.
while (reader.Read())
{
Console.WriteLine(String.Format("{0}, {1}",
reader[0], reader[1]));
}
// Call Close when done reading.
reader.Close();
}
}

Información de versión
.NET FrameworkCompatible con: 4, 3.5, 3.0, 2.0, 1.1, 1.0 .NET Framework Client ProfileCompatible con: 4, 3.5 SP1

Plataformas
Windows 7, Windows Vista SP1 o posterior, Windows XP SP3, Windows XP SP2 x64 Edition, Windows Server 2008 (no se admite Server Core), Windows Server 2008 R2 (se admite Server Core con SP1 o posterior), Windows Server 2003 SP2
.NET Framework no admite todas las versiones de todas las plataformas. Para obtener una lista de las versiones compatibles, vea Requisitos de sistema de .NET Framework.

Vea también
|