Permalink
Fetching contributors…
Cannot retrieve contributors at this time
383 lines (350 sloc) 20.6 KB
<Type Name="IDataReader" FullName="System.Data.IDataReader">
<TypeSignature Language="C#" Value="public interface IDataReader : IDisposable, System.Data.IDataRecord" />
<TypeSignature Language="ILAsm" Value=".class public interface auto ansi abstract IDataReader implements class System.Data.IDataRecord, class System.IDisposable" />
<TypeSignature Language="DocId" Value="T:System.Data.IDataReader" />
<TypeSignature Language="VB.NET" Value="Public Interface IDataReader&#xA;Implements IDataRecord, IDisposable" />
<TypeSignature Language="C++ CLI" Value="public interface class IDataReader : IDisposable, System::Data::IDataRecord" />
<TypeSignature Language="F#" Value="type IDataReader = interface&#xA; interface IDisposable&#xA; interface IDataRecord" />
<AssemblyInfo>
<AssemblyName>System.Data.Common</AssemblyName>
<AssemblyVersion>4.1.0.0</AssemblyVersion>
<AssemblyVersion>4.2.0.0</AssemblyVersion>
<AssemblyVersion>4.2.1.0</AssemblyVersion>
</AssemblyInfo>
<AssemblyInfo>
<AssemblyName>System.Data</AssemblyName>
<AssemblyVersion>1.0.5000.0</AssemblyVersion>
<AssemblyVersion>2.0.0.0</AssemblyVersion>
<AssemblyVersion>2.0.5.0</AssemblyVersion>
<AssemblyVersion>4.0.0.0</AssemblyVersion>
</AssemblyInfo>
<AssemblyInfo>
<AssemblyName>netstandard</AssemblyName>
<AssemblyVersion>2.0.0.0</AssemblyVersion>
</AssemblyInfo>
<Interfaces>
<Interface>
<InterfaceName>System.Data.IDataRecord</InterfaceName>
</Interface>
<Interface>
<InterfaceName>System.IDisposable</InterfaceName>
</Interface>
</Interfaces>
<Docs>
<summary>Provides a means of reading one or more forward-only streams of result sets obtained by executing a command at a data source, and is implemented by .NET Framework data providers that access relational databases.</summary>
<remarks>
<format type="text/markdown"><![CDATA[
## Remarks
The <xref:System.Data.IDataReader> and <xref:System.Data.IDataRecord> interfaces allow an inheriting class to implement a `DataReader` class, which provides a means of reading one or more forward-only streams of result sets. For more information about `DataReader` classes, see [Retrieving Data Using a DataReader](~/docs/framework/data/adonet/retrieving-data-using-a-datareader.md).
An application does not create an instance of the <xref:System.Data.IDataReader> interface directly, but creates an instance of a class that inherits <xref:System.Data.IDataReader>.
Classes that inherit <xref:System.Data.IDataReader> must implement the inherited members, and typically define additional members to add provider-specific functionality.
Changes made to a result set by another process or thread while data is being read may be visible to the user of a class that implements an `IDataReader`. However, the precise behavior is both provider and timing dependent.
## Examples
The following example creates instances of the derived classes, <xref:System.Data.SqlClient.SqlConnection>, <xref:System.Data.SqlClient.SqlCommand>, and <xref:System.Data.SqlClient.SqlDataReader>. The example reads through the data, writing it out to the console. Finally, the example closes the <xref:System.Data.SqlClient.SqlDataReader>, then the <xref:System.Data.SqlClient.SqlConnection>.
[!code-csharp[Classic WebData SqlDataReader.Read Example#1](~/samples/snippets/csharp/VS_Snippets_ADO.NET/Classic WebData SqlDataReader.Read Example/CS/source.cs#1)]
[!code-vb[Classic WebData SqlDataReader.Read Example#1](~/samples/snippets/visualbasic/VS_Snippets_ADO.NET/Classic WebData SqlDataReader.Read Example/VB/source.vb#1)]
]]></format>
</remarks>
<block subset="none" type="overrides">
<para>To promote consistency among .NET Framework data providers, name the inheriting class in the form <paramref name="Prv" /> Command where <paramref name="Prv" /> is the uniform prefix given to all classes in a specific .NET Framework data provider namespace. For example, <paramref name="Sql" /> is the prefix of the <see cref="T:System.Data.SqlClient.SqlDataAdapter" /> class in the <see langword="System.Data.SqlClient" /> namespace.
Users do not create an instance of a <see langword="DataReader" /> class directly. Instead, they obtain the <see langword="DataReader" /> instance through the <see langword="ExecuteReader" /> method of the <see langword="Command" /> object. Therefore, you should mark <see langword="DataReader" /> constructors as internal.</para>
</block>
</Docs>
<Members>
<Member MemberName="Close">
<MemberSignature Language="C#" Value="public void Close ();" />
<MemberSignature Language="ILAsm" Value=".method public hidebysig newslot virtual instance void Close() cil managed" />
<MemberSignature Language="DocId" Value="M:System.Data.IDataReader.Close" />
<MemberSignature Language="VB.NET" Value="Public Sub Close ()" />
<MemberSignature Language="C++ CLI" Value="public:&#xA; void Close();" />
<MemberSignature Language="F#" Value="abstract member Close : unit -&gt; unit" Usage="iDataReader.Close " />
<MemberType>Method</MemberType>
<AssemblyInfo>
<AssemblyName>System.Data.Common</AssemblyName>
<AssemblyVersion>4.1.0.0</AssemblyVersion>
<AssemblyVersion>4.2.0.0</AssemblyVersion>
<AssemblyVersion>4.2.1.0</AssemblyVersion>
</AssemblyInfo>
<AssemblyInfo>
<AssemblyName>System.Data</AssemblyName>
<AssemblyVersion>1.0.5000.0</AssemblyVersion>
<AssemblyVersion>2.0.0.0</AssemblyVersion>
<AssemblyVersion>2.0.5.0</AssemblyVersion>
<AssemblyVersion>4.0.0.0</AssemblyVersion>
</AssemblyInfo>
<AssemblyInfo>
<AssemblyName>netstandard</AssemblyName>
<AssemblyVersion>2.0.0.0</AssemblyVersion>
</AssemblyInfo>
<ReturnValue>
<ReturnType>System.Void</ReturnType>
</ReturnValue>
<Parameters />
<Docs>
<summary>Closes the <see cref="T:System.Data.IDataReader" /> Object.</summary>
<remarks>
<format type="text/markdown"><![CDATA[
## Remarks
You must explicitly call the <xref:System.Data.IDataReader.Close%2A> method when you are through using the <xref:System.Data.IDataReader> to use the associated <xref:System.Data.IDbConnection> for any other purpose.
]]></format>
</remarks>
</Docs>
</Member>
<Member MemberName="Depth">
<MemberSignature Language="C#" Value="public int Depth { get; }" />
<MemberSignature Language="ILAsm" Value=".property instance int32 Depth" />
<MemberSignature Language="DocId" Value="P:System.Data.IDataReader.Depth" />
<MemberSignature Language="VB.NET" Value="Public ReadOnly Property Depth As Integer" />
<MemberSignature Language="C++ CLI" Value="public:&#xA; property int Depth { int get(); };" />
<MemberSignature Language="F#" Value="member this.Depth : int" Usage="System.Data.IDataReader.Depth" />
<MemberType>Property</MemberType>
<AssemblyInfo>
<AssemblyName>System.Data.Common</AssemblyName>
<AssemblyVersion>4.1.0.0</AssemblyVersion>
<AssemblyVersion>4.2.0.0</AssemblyVersion>
<AssemblyVersion>4.2.1.0</AssemblyVersion>
</AssemblyInfo>
<AssemblyInfo>
<AssemblyName>System.Data</AssemblyName>
<AssemblyVersion>1.0.5000.0</AssemblyVersion>
<AssemblyVersion>2.0.0.0</AssemblyVersion>
<AssemblyVersion>2.0.5.0</AssemblyVersion>
<AssemblyVersion>4.0.0.0</AssemblyVersion>
</AssemblyInfo>
<AssemblyInfo>
<AssemblyName>netstandard</AssemblyName>
<AssemblyVersion>2.0.0.0</AssemblyVersion>
</AssemblyInfo>
<ReturnValue>
<ReturnType>System.Int32</ReturnType>
</ReturnValue>
<Docs>
<summary>Gets a value indicating the depth of nesting for the current row.</summary>
<value>The level of nesting.</value>
<remarks>
<format type="text/markdown"><![CDATA[
## Remarks
The outermost table has a depth of zero.
]]></format>
</remarks>
</Docs>
</Member>
<Member MemberName="GetSchemaTable">
<MemberSignature Language="C#" Value="public System.Data.DataTable GetSchemaTable ();" />
<MemberSignature Language="ILAsm" Value=".method public hidebysig newslot virtual instance class System.Data.DataTable GetSchemaTable() cil managed" />
<MemberSignature Language="DocId" Value="M:System.Data.IDataReader.GetSchemaTable" />
<MemberSignature Language="VB.NET" Value="Public Function GetSchemaTable () As DataTable" />
<MemberSignature Language="C++ CLI" Value="public:&#xA; System::Data::DataTable ^ GetSchemaTable();" />
<MemberSignature Language="F#" Value="abstract member GetSchemaTable : unit -&gt; System.Data.DataTable" Usage="iDataReader.GetSchemaTable " />
<MemberType>Method</MemberType>
<AssemblyInfo>
<AssemblyName>System.Data.Common</AssemblyName>
<AssemblyVersion>4.1.0.0</AssemblyVersion>
<AssemblyVersion>4.2.0.0</AssemblyVersion>
<AssemblyVersion>4.2.1.0</AssemblyVersion>
</AssemblyInfo>
<AssemblyInfo>
<AssemblyName>System.Data</AssemblyName>
<AssemblyVersion>1.0.5000.0</AssemblyVersion>
<AssemblyVersion>2.0.0.0</AssemblyVersion>
<AssemblyVersion>2.0.5.0</AssemblyVersion>
<AssemblyVersion>4.0.0.0</AssemblyVersion>
</AssemblyInfo>
<AssemblyInfo>
<AssemblyName>netstandard</AssemblyName>
<AssemblyVersion>2.0.0.0</AssemblyVersion>
</AssemblyInfo>
<ReturnValue>
<ReturnType>System.Data.DataTable</ReturnType>
</ReturnValue>
<Parameters />
<Docs>
<summary>Returns a <see cref="T:System.Data.DataTable" /> that describes the column metadata of the <see cref="T:System.Data.IDataReader" />.</summary>
<returns>A <see cref="T:System.Data.DataTable" /> that describes the column metadata.</returns>
<remarks>
<format type="text/markdown"><![CDATA[
## Remarks
The implementation of <xref:System.Data.IDataReader.GetSchemaTable%2A> method for the .NET Framework Data Provider for OLE DB maps to the OLE DB IColumnsRowset::GetColumnsRowset method, while implementations for other .NET Framework data providers do not use an OLE DB provider layer. The order in which <xref:System.Data.IDataReader.GetSchemaTable%2A> returns metadata about each column in a table, and the DataReader columns that are returned, vary depending on which data provider you use. The following table lists data providers and members that implement <xref:System.Data.IDataReader.GetSchemaTable%2A>.
|Data Provider|Member|
|-------------------|------------|
|.NET Data Provider for ODBC|<xref:System.Data.Odbc.OdbcDataReader.GetSchemaTable%2A?displayProperty=nameWithType>.|
|.NET Data Provider for OLE DB|<xref:System.Data.OleDb.OleDbDataReader.GetSchemaTable%2A?displayProperty=nameWithType>.|
|.NET Data Provider for Oracle|<xref:System.Data.OracleClient.OracleDataReader.GetSchemaTable%2A?displayProperty=nameWithType>.|
|.NET Data Provider for SQL Server|<xref:System.Data.SqlClient.SqlDataReader.GetSchemaTable%2A?displayProperty=nameWithType>.|
]]></format>
</remarks>
<exception cref="T:System.InvalidOperationException">The <see cref="T:System.Data.IDataReader" /> is closed.</exception>
</Docs>
</Member>
<Member MemberName="IsClosed">
<MemberSignature Language="C#" Value="public bool IsClosed { get; }" />
<MemberSignature Language="ILAsm" Value=".property instance bool IsClosed" />
<MemberSignature Language="DocId" Value="P:System.Data.IDataReader.IsClosed" />
<MemberSignature Language="VB.NET" Value="Public ReadOnly Property IsClosed As Boolean" />
<MemberSignature Language="C++ CLI" Value="public:&#xA; property bool IsClosed { bool get(); };" />
<MemberSignature Language="F#" Value="member this.IsClosed : bool" Usage="System.Data.IDataReader.IsClosed" />
<MemberType>Property</MemberType>
<AssemblyInfo>
<AssemblyName>System.Data.Common</AssemblyName>
<AssemblyVersion>4.1.0.0</AssemblyVersion>
<AssemblyVersion>4.2.0.0</AssemblyVersion>
<AssemblyVersion>4.2.1.0</AssemblyVersion>
</AssemblyInfo>
<AssemblyInfo>
<AssemblyName>System.Data</AssemblyName>
<AssemblyVersion>1.0.5000.0</AssemblyVersion>
<AssemblyVersion>2.0.0.0</AssemblyVersion>
<AssemblyVersion>2.0.5.0</AssemblyVersion>
<AssemblyVersion>4.0.0.0</AssemblyVersion>
</AssemblyInfo>
<AssemblyInfo>
<AssemblyName>netstandard</AssemblyName>
<AssemblyVersion>2.0.0.0</AssemblyVersion>
</AssemblyInfo>
<ReturnValue>
<ReturnType>System.Boolean</ReturnType>
</ReturnValue>
<Docs>
<summary>Gets a value indicating whether the data reader is closed.</summary>
<value>
<see langword="true" /> if the data reader is closed; otherwise, <see langword="false" />.</value>
<remarks>
<format type="text/markdown"><![CDATA[
## Remarks
<xref:System.Data.IDataReader.IsClosed%2A> and <xref:System.Data.IDataReader.RecordsAffected%2A> are the only properties that you can call after the <xref:System.Data.IDataReader> is closed.
]]></format>
</remarks>
</Docs>
</Member>
<Member MemberName="NextResult">
<MemberSignature Language="C#" Value="public bool NextResult ();" />
<MemberSignature Language="ILAsm" Value=".method public hidebysig newslot virtual instance bool NextResult() cil managed" />
<MemberSignature Language="DocId" Value="M:System.Data.IDataReader.NextResult" />
<MemberSignature Language="VB.NET" Value="Public Function NextResult () As Boolean" />
<MemberSignature Language="C++ CLI" Value="public:&#xA; bool NextResult();" />
<MemberSignature Language="F#" Value="abstract member NextResult : unit -&gt; bool" Usage="iDataReader.NextResult " />
<MemberType>Method</MemberType>
<AssemblyInfo>
<AssemblyName>System.Data.Common</AssemblyName>
<AssemblyVersion>4.1.0.0</AssemblyVersion>
<AssemblyVersion>4.2.0.0</AssemblyVersion>
<AssemblyVersion>4.2.1.0</AssemblyVersion>
</AssemblyInfo>
<AssemblyInfo>
<AssemblyName>System.Data</AssemblyName>
<AssemblyVersion>1.0.5000.0</AssemblyVersion>
<AssemblyVersion>2.0.0.0</AssemblyVersion>
<AssemblyVersion>2.0.5.0</AssemblyVersion>
<AssemblyVersion>4.0.0.0</AssemblyVersion>
</AssemblyInfo>
<AssemblyInfo>
<AssemblyName>netstandard</AssemblyName>
<AssemblyVersion>2.0.0.0</AssemblyVersion>
</AssemblyInfo>
<ReturnValue>
<ReturnType>System.Boolean</ReturnType>
</ReturnValue>
<Parameters />
<Docs>
<summary>Advances the data reader to the next result, when reading the results of batch SQL statements.</summary>
<returns>
<see langword="true" /> if there are more rows; otherwise, <see langword="false" />.</returns>
<remarks>
<format type="text/markdown"><![CDATA[
## Remarks
Used to process multiple results, which can be obtained by executing batch SQL statements.
By default, the data reader is positioned on the first result.
[!code-csharp[IDataReader_NextResult#1](~/samples/snippets/csharp/VS_Snippets_ADO.NET/idatareader_nextresult/cs/source.cs#1)]
[!code-vb[IDataReader_NextResult#1](~/samples/snippets/visualbasic/VS_Snippets_ADO.NET/idatareader_nextresult/vb/source.vb#1)]
]]></format>
</remarks>
</Docs>
</Member>
<Member MemberName="Read">
<MemberSignature Language="C#" Value="public bool Read ();" />
<MemberSignature Language="ILAsm" Value=".method public hidebysig newslot virtual instance bool Read() cil managed" />
<MemberSignature Language="DocId" Value="M:System.Data.IDataReader.Read" />
<MemberSignature Language="VB.NET" Value="Public Function Read () As Boolean" />
<MemberSignature Language="C++ CLI" Value="public:&#xA; bool Read();" />
<MemberSignature Language="F#" Value="abstract member Read : unit -&gt; bool" Usage="iDataReader.Read " />
<MemberType>Method</MemberType>
<AssemblyInfo>
<AssemblyName>System.Data.Common</AssemblyName>
<AssemblyVersion>4.1.0.0</AssemblyVersion>
<AssemblyVersion>4.2.0.0</AssemblyVersion>
<AssemblyVersion>4.2.1.0</AssemblyVersion>
</AssemblyInfo>
<AssemblyInfo>
<AssemblyName>System.Data</AssemblyName>
<AssemblyVersion>1.0.5000.0</AssemblyVersion>
<AssemblyVersion>2.0.0.0</AssemblyVersion>
<AssemblyVersion>2.0.5.0</AssemblyVersion>
<AssemblyVersion>4.0.0.0</AssemblyVersion>
</AssemblyInfo>
<AssemblyInfo>
<AssemblyName>netstandard</AssemblyName>
<AssemblyVersion>2.0.0.0</AssemblyVersion>
</AssemblyInfo>
<ReturnValue>
<ReturnType>System.Boolean</ReturnType>
</ReturnValue>
<Parameters />
<Docs>
<summary>Advances the <see cref="T:System.Data.IDataReader" /> to the next record.</summary>
<returns>
<see langword="true" /> if there are more rows; otherwise, <see langword="false" />.</returns>
<remarks>
<format type="text/markdown"><![CDATA[
## Remarks
The default position of the <xref:System.Data.IDataReader> is prior to the first record. Therefore you must call <xref:System.Data.IDataReader.Read%2A> to begin accessing any data.
While the data reader is in use, the associated connection is busy serving the <xref:System.Data.IDataReader>. This is the case until <xref:System.Data.IDataReader.Close%2A> is called.
## Examples
The following example creates instances of three derived classes <xref:System.Data.OleDb.OleDbConnection>, an <xref:System.Data.OleDb.OleDbCommand>, and an <xref:System.Data.OleDb.OleDbDataReader>. The example reads through the data, writing it out to the console. Finally, the example closes the <xref:System.Data.OleDb.OleDbDataReader>, then the <xref:System.Data.OleDb.OleDbConnection>.
[!code-csharp[Classic WebData IDataReader.Read Example#1](~/samples/snippets/csharp/VS_Snippets_ADO.NET/Classic WebData IDataReader.Read Example/CS/source.cs#1)]
[!code-vb[Classic WebData IDataReader.Read Example#1](~/samples/snippets/visualbasic/VS_Snippets_ADO.NET/Classic WebData IDataReader.Read Example/VB/source.vb#1)]
]]></format>
</remarks>
</Docs>
</Member>
<Member MemberName="RecordsAffected">
<MemberSignature Language="C#" Value="public int RecordsAffected { get; }" />
<MemberSignature Language="ILAsm" Value=".property instance int32 RecordsAffected" />
<MemberSignature Language="DocId" Value="P:System.Data.IDataReader.RecordsAffected" />
<MemberSignature Language="VB.NET" Value="Public ReadOnly Property RecordsAffected As Integer" />
<MemberSignature Language="C++ CLI" Value="public:&#xA; property int RecordsAffected { int get(); };" />
<MemberSignature Language="F#" Value="member this.RecordsAffected : int" Usage="System.Data.IDataReader.RecordsAffected" />
<MemberType>Property</MemberType>
<AssemblyInfo>
<AssemblyName>System.Data.Common</AssemblyName>
<AssemblyVersion>4.1.0.0</AssemblyVersion>
<AssemblyVersion>4.2.0.0</AssemblyVersion>
<AssemblyVersion>4.2.1.0</AssemblyVersion>
</AssemblyInfo>
<AssemblyInfo>
<AssemblyName>System.Data</AssemblyName>
<AssemblyVersion>1.0.5000.0</AssemblyVersion>
<AssemblyVersion>2.0.0.0</AssemblyVersion>
<AssemblyVersion>2.0.5.0</AssemblyVersion>
<AssemblyVersion>4.0.0.0</AssemblyVersion>
</AssemblyInfo>
<AssemblyInfo>
<AssemblyName>netstandard</AssemblyName>
<AssemblyVersion>2.0.0.0</AssemblyVersion>
</AssemblyInfo>
<ReturnValue>
<ReturnType>System.Int32</ReturnType>
</ReturnValue>
<Docs>
<summary>Gets the number of rows changed, inserted, or deleted by execution of the SQL statement.</summary>
<value>The number of rows changed, inserted, or deleted; 0 if no rows were affected or the statement failed; and -1 for SELECT statements.</value>
<remarks>
<format type="text/markdown"><![CDATA[
## Remarks
The <xref:System.Data.IDataReader.RecordsAffected%2A> property is not set until all rows are read and you close the <xref:System.Data.IDataReader>.
<xref:System.Data.IDataReader.IsClosed%2A> and <xref:System.Data.IDataReader.RecordsAffected%2A> are the only properties that you can call after the <xref:System.Data.IDataReader> is closed.
]]></format>
</remarks>
</Docs>
</Member>
</Members>
</Type>