OdbcDataReader OdbcDataReader OdbcDataReader OdbcDataReader Class

Definition

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

public ref class OdbcDataReader sealed : System::Data::Common::DbDataReader
public sealed class OdbcDataReader : System.Data.Common.DbDataReader
type OdbcDataReader = class
    inherit DbDataReader
Public NotInheritable Class OdbcDataReader
Inherits DbDataReader
Inheritance

Examples

The following example creates an OdbcConnection, an OdbcCommand, and an OdbcDataReader. The example reads through the data, writing it out to the console. Finally, the example closes the OdbcDataReader, and then the OdbcConnection.

public static void ReadData(string connectionString)
{
    string queryString = "SELECT DISTINCT CustomerID FROM Orders";

    using (OdbcConnection connection = new OdbcConnection(connectionString))
    {
        OdbcCommand command = new OdbcCommand(queryString, connection);

        connection.Open();

        // Execute the DataReader and access the data.
        OdbcDataReader reader = command.ExecuteReader();
        while (reader.Read())
        {
            Console.WriteLine("CustomerID={0}", reader[0]);
        }

        // Call Close when done reading.
        reader.Close();
    }
}
Public Sub ReadData(ByVal connectionString As String)
    Dim queryString As String = "SELECT DISTINCT CustomerID FROM Orders"

    Using connection As New OdbcConnection(connectionString)
        Dim command As New OdbcCommand(queryString, connection)

        connection.Open()

        Dim reader As OdbcDataReader = command.ExecuteReader()

        While reader.Read()
            Console.WriteLine("CustomerID={0}", reader(0).ToString)
        End While

        ' Call Close when done reading.
        reader.Close()
    End Using
End Sub

Remarks

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

While the OdbcDataReader is being used, the associated OdbcConnection is busy serving the OdbcDataReader, and no other operations can be performed on the OdbcConnection other than closing it. This is the case until the Close method of the OdbcDataReader 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 OdbcDataReader. However, the precise behavior is both driver and timing dependent.

IsClosed and RecordsAffected are the only properties that you can call after the OdbcDataReader is closed. Sometimes, you must call Close before you can call RecordsAffected.

Properties

Depth Depth Depth Depth

Gets a value that indicates the depth of nesting for the current row.

FieldCount FieldCount FieldCount FieldCount

Gets the number of columns in the current row.

HasRows HasRows HasRows HasRows

Gets a value that indicates whether the OdbcDataReader contains one or more rows.

IsClosed IsClosed IsClosed IsClosed

Indicates whether the OdbcDataReader is closed.

Item[Int32] Item[Int32] Item[Int32] Item[Int32]

Gets the value of the specified column in its native format given the column ordinal.

Item[String] Item[String] Item[String] Item[String]

Gets the value of the specified column in its native format given the column name.

RecordsAffected RecordsAffected RecordsAffected RecordsAffected

Gets the number of rows changed, inserted, or deleted by execution of the SQL statement.

Methods

Close() Close() Close() Close()

Closes the OdbcDataReader object.

CreateObjRef(Type) CreateObjRef(Type) CreateObjRef(Type) CreateObjRef(Type)

Creates an object that contains all the relevant information required to generate a proxy used to communicate with a remote object.

(Inherited from MarshalByRefObject)
Equals(Object) Equals(Object) Equals(Object) Equals(Object)

Determines whether the specified object is equal to the current object.

(Inherited from Object)
Finalize() Finalize() Finalize() Finalize()
GetBoolean(Int32) GetBoolean(Int32) GetBoolean(Int32) GetBoolean(Int32)

Gets the value of the specified column as a Boolean.

GetByte(Int32) GetByte(Int32) GetByte(Int32) GetByte(Int32)

Gets the value of the specified column as a byte.

GetBytes(Int32, Int64, Byte[], Int32, Int32) GetBytes(Int32, Int64, Byte[], Int32, Int32) GetBytes(Int32, Int64, Byte[], Int32, Int32) GetBytes(Int32, Int64, Byte[], Int32, Int32)

Reads a stream of bytes from the specified column offset into the buffer as an array, starting at the particular buffer offset.

GetChar(Int32) GetChar(Int32) GetChar(Int32) GetChar(Int32)

Gets the value of the specified column as a character.

GetChars(Int32, Int64, Char[], Int32, Int32) GetChars(Int32, Int64, Char[], Int32, Int32) GetChars(Int32, Int64, Char[], Int32, Int32) GetChars(Int32, Int64, Char[], Int32, Int32)

Reads a stream of characters from the specified column offset into the buffer as an array, starting at the particular buffer offset.

GetData(Int32) GetData(Int32) GetData(Int32) GetData(Int32)
GetDataTypeName(Int32) GetDataTypeName(Int32) GetDataTypeName(Int32) GetDataTypeName(Int32)

Gets the name of the source data type.

GetDate(Int32) GetDate(Int32) GetDate(Int32) GetDate(Int32)

Gets the value of the specified column as a DateTime object.

GetDateTime(Int32) GetDateTime(Int32) GetDateTime(Int32) GetDateTime(Int32)

Gets the value of the specified column as a DateTime object.

GetDecimal(Int32) GetDecimal(Int32) GetDecimal(Int32) GetDecimal(Int32)

Gets the value of the specified column as a Decimal object.

GetDouble(Int32) GetDouble(Int32) GetDouble(Int32) GetDouble(Int32)

Gets the value of the specified column as a double-precision floating-point number.

GetEnumerator() GetEnumerator() GetEnumerator() GetEnumerator()

Returns an IEnumerator that can be used to iterate through the rows in the data reader.

GetFieldType(Int32) GetFieldType(Int32) GetFieldType(Int32) GetFieldType(Int32)

Gets the Type that is the data type of the object.

GetFloat(Int32) GetFloat(Int32) GetFloat(Int32) GetFloat(Int32)

Gets the value of the specified column as a single-precision floating-point number.

GetGuid(Int32) GetGuid(Int32) GetGuid(Int32) GetGuid(Int32)

Gets the value of the specified column as a globally unique identifier (GUID).

GetHashCode() GetHashCode() GetHashCode() GetHashCode()

Serves as the default hash function.

(Inherited from Object)
GetInt16(Int32) GetInt16(Int32) GetInt16(Int32) GetInt16(Int32)

Gets the value of the specified column as a 16-bit signed integer.

GetInt32(Int32) GetInt32(Int32) GetInt32(Int32) GetInt32(Int32)

Gets the value of the specified column as a 32-bit signed integer.

GetInt64(Int32) GetInt64(Int32) GetInt64(Int32) GetInt64(Int32)

Gets the value of the specified column as a 64-bit signed integer.

GetLifetimeService() GetLifetimeService() GetLifetimeService() GetLifetimeService()

Retrieves the current lifetime service object that controls the lifetime policy for this instance.

(Inherited from MarshalByRefObject)
GetName(Int32) GetName(Int32) GetName(Int32) GetName(Int32)

Gets the name of the specified column.

GetOrdinal(String) GetOrdinal(String) GetOrdinal(String) GetOrdinal(String)

Gets the column ordinal, given the name of the column.

GetSchemaTable() GetSchemaTable() GetSchemaTable() GetSchemaTable()

Returns a DataTable that describes the column metadata of the OdbcDataReader.

GetString(Int32) GetString(Int32) GetString(Int32) GetString(Int32)

Gets the value of the specified column as a String.

GetTime(Int32) GetTime(Int32) GetTime(Int32) GetTime(Int32)

Gets the value of the specified column as a TimeSpan object.

GetType() GetType() GetType() GetType()

Gets the Type of the current instance.

(Inherited from Object)
GetValue(Int32) GetValue(Int32) GetValue(Int32) GetValue(Int32)

Gets the value of the column at the specified ordinal in its native format.

GetValues(Object[]) GetValues(Object[]) GetValues(Object[]) GetValues(Object[])

Populates an array of objects with the column values of the current row.

InitializeLifetimeService() InitializeLifetimeService() InitializeLifetimeService() InitializeLifetimeService()

Obtains a lifetime service object to control the lifetime policy for this instance.

(Inherited from MarshalByRefObject)
IsDBNull(Int32) IsDBNull(Int32) IsDBNull(Int32) IsDBNull(Int32)

Gets a value that indicates whether the column contains nonexistent or missing values.

MemberwiseClone() MemberwiseClone() MemberwiseClone() MemberwiseClone()

Creates a shallow copy of the current Object.

(Inherited from Object)
MemberwiseClone(Boolean) MemberwiseClone(Boolean) MemberwiseClone(Boolean) MemberwiseClone(Boolean)

Creates a shallow copy of the current MarshalByRefObject object.

(Inherited from MarshalByRefObject)
NextResult() NextResult() NextResult() NextResult()

Advances the OdbcDataReader to the next result when reading the results of batch SQL statements.

Read() Read() Read() Read()

Advances the OdbcDataReader to the next record.

ToString() ToString() ToString() ToString()

Returns a string that represents the current object.

(Inherited from Object)

Explicit Interface Implementations

IDisposable.Dispose() IDisposable.Dispose() IDisposable.Dispose() IDisposable.Dispose()
IEnumerable.GetEnumerator() IEnumerable.GetEnumerator() IEnumerable.GetEnumerator() IEnumerable.GetEnumerator()

Applies to

See also