Export (0) Print
Expand All

OleDbDataReader Class

Provides a way of reading a forward-only stream of data rows from a data source. This class cannot be inherited.

Namespace: System.Data.OleDb
Assembly: System.Data (in system.data.dll)

'Declaration
Public NotInheritable Class OleDbDataReader
	Inherits DbDataReader
'Usage
Dim instance As OleDbDataReader

public final class OleDbDataReader extends DbDataReader
public final class OleDbDataReader extends DbDataReader

To create an OleDbDataReader, you must call the ExecuteReader method of the OleDbCommand object, instead of directly using a constructor.

While the OleDbDataReader is being used, the associated OleDbConnection is busy serving the OleDbDataReader, and no other operations can be performed on the OleDbConnection other than closing it. This is the case until the Close method of the OleDbDataReader is called. For example, you cannot retrieve output parameters until after you call Close.

Changes made to a result set by another process or thread while data is being read may be visible to the user of the OleDbDataReader. However, the precise behavior is timing dependent.

IsClosed and RecordsAffected are the only properties that you can call after the OleDbDataReader is closed. Although the RecordsAffected property may be accessed while the OleDbDataReader exists, always call Close before returning the value of RecordsAffected to guarantee an accurate return value.

The following example creates an OleDbConnection, an OleDbCommand, and an OleDbDataReader. The example reads through the data, writing it out to the console. Finally, the example closes the OleDbDataReader and then the OleDbConnection.

Public Sub ReadData(ByVal connectionString As String, _
    ByVal queryString As String)
    Using connection As New OleDbConnection(connectionString)
        Dim command As New OleDbCommand(queryString, connection)

        connection.Open()

        Dim reader As OleDbDataReader = command.ExecuteReader()
        While reader.Read()
            Console.WriteLine(reader(0).ToString())
        End While
        reader.Close()
    End Using
End Sub

using System;
using System.Data;
using System.Data.OleDb;

class Class1
{
    static void Main()
    {
        //string x = "Provider=SQLOLEDB;Data Source=(local);Integrated Security=SSPI;Initial Catalog=Northwind";
        //ReadData(x);
    

    public static void ReadData(string connectionString, string queryString)
    {
        using (OleDbConnection connection = new OleDbConnection(connectionString))
        {
            OleDbCommand command = new OleDbCommand(queryString, connection);

            connection.Open();
            OleDbDataReader reader = command.ExecuteReader();

            while (reader.Read())
            {
                Console.WriteLine(reader[0].ToString());
            
            reader.Close();
        
    

System.Object
   System.MarshalByRefObject
     System.Data.Common.DbDataReader
      System.Data.OleDb.OleDbDataReader

Any public static (Shared in Visual Basic) members of this type are thread safe. Any instance members are not guaranteed to be thread safe.

Windows 98, Windows 2000 SP4, Windows Millennium Edition, Windows Server 2003, Windows XP Media Center Edition, Windows XP Professional x64 Edition, Windows XP SP2, Windows XP Starter Edition

The .NET Framework does not support all versions of every platform. For a list of the supported versions, see System Requirements.

.NET Framework

Supported in: 2.0, 1.1, 1.0

Community Additions

ADD
Show:
© 2014 Microsoft