Export (0) Print
Expand All

OdbcDataReader 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.Odbc
Assembly:  System.Data (in System.Data.dll)

public sealed class OdbcDataReader : DbDataReader

The OdbcDataReader type exposes the following members.

  NameDescription
Public propertyDepthGets a value that indicates the depth of nesting for the current row. (Overrides DbDataReader.Depth.)
Public propertyFieldCountGets the number of columns in the current row. (Overrides DbDataReader.FieldCount.)
Public propertyHasRowsGets a value that indicates whether the OdbcDataReader contains one or more rows. (Overrides DbDataReader.HasRows.)
Public propertyIsClosedIndicates whether the OdbcDataReader is closed. (Overrides DbDataReader.IsClosed.)
Public propertyItem[Int32]Gets the value of the specified column in its native format given the column ordinal. (Overrides DbDataReader.Item[Int32].)
Public propertyItem[String]Gets the value of the specified column in its native format given the column name. (Overrides DbDataReader.Item[String].)
Public propertyRecordsAffectedGets the number of rows changed, inserted, or deleted by execution of the SQL statement. (Overrides DbDataReader.RecordsAffected.)
Public propertyVisibleFieldCountGets the number of fields in the DbDataReader that are not hidden. (Inherited from DbDataReader.)
Top

  NameDescription
Public methodCloseCloses the OdbcDataReader object. (Overrides DbDataReader.Close().)
Public methodCreateObjRefCreates an object that contains all the relevant information required to generate a proxy used to communicate with a remote object. (Inherited from MarshalByRefObject.)
Public methodDispose()Releases all resources used by the current instance of the DbDataReader class. (Inherited from DbDataReader.)
Protected methodDispose(Boolean)Releases the managed resources used by the DbDataReader and optionally releases the unmanaged resources. (Inherited from DbDataReader.)
Public methodEquals(Object)Determines whether the specified Object is equal to the current Object. (Inherited from Object.)
Protected methodFinalizeAllows an object to try to free resources and perform other cleanup operations before it is reclaimed by garbage collection. (Inherited from Object.)
Public methodGetBooleanGets the value of the specified column as a Boolean. (Overrides DbDataReader.GetBoolean(Int32).)
Public methodGetByteGets the value of the specified column as a byte. (Overrides DbDataReader.GetByte(Int32).)
Public methodGetBytesReads a stream of bytes from the specified column offset into the buffer as an array, starting at the particular buffer offset. (Overrides DbDataReader.GetBytes(Int32, Int64, Byte[], Int32, Int32).)
Public methodGetCharGets the value of the specified column as a character. (Overrides DbDataReader.GetChar(Int32).)
Public methodGetCharsReads a stream of characters from the specified column offset into the buffer as an array, starting at the particular buffer offset. (Overrides DbDataReader.GetChars(Int32, Int64, Char[], Int32, Int32).)
Public methodGetDataReturns a DbDataReader object for the requested column ordinal. (Inherited from DbDataReader.)
Public methodGetDataTypeNameGets the name of the source data type. (Overrides DbDataReader.GetDataTypeName(Int32).)
Public methodGetDateGets the value of the specified column as a DateTime object.
Public methodGetDateTimeGets the value of the specified column as a DateTime object. (Overrides DbDataReader.GetDateTime(Int32).)
Protected methodGetDbDataReaderReturns a DbDataReader object for the requested column ordinal that can be overridden with a provider-specific implementation. (Inherited from DbDataReader.)
Public methodGetDecimalGets the value of the specified column as a Decimal object. (Overrides DbDataReader.GetDecimal(Int32).)
Public methodGetDoubleGets the value of the specified column as a double-precision floating-point number. (Overrides DbDataReader.GetDouble(Int32).)
Public methodGetEnumeratorReturns an IEnumerator that can be used to iterate through the rows in the data reader. (Overrides DbDataReader.GetEnumerator().)
Public methodGetFieldTypeGets the Type that is the data type of the object. (Overrides DbDataReader.GetFieldType(Int32).)
Public methodGetFloatGets the value of the specified column as a single-precision floating-point number. (Overrides DbDataReader.GetFloat(Int32).)
Public methodGetGuidGets the value of the specified column as a globally unique identifier (GUID). (Overrides DbDataReader.GetGuid(Int32).)
Public methodGetHashCodeServes as a hash function for a particular type. (Inherited from Object.)
Public methodGetInt16Gets the value of the specified column as a 16-bit signed integer. (Overrides DbDataReader.GetInt16(Int32).)
Public methodGetInt32Gets the value of the specified column as a 32-bit signed integer. (Overrides DbDataReader.GetInt32(Int32).)
Public methodGetInt64Gets the value of the specified column as a 64-bit signed integer. (Overrides DbDataReader.GetInt64(Int32).)
Public methodGetLifetimeServiceRetrieves the current lifetime service object that controls the lifetime policy for this instance. (Inherited from MarshalByRefObject.)
Public methodGetNameGets the name of the specified column. (Overrides DbDataReader.GetName(Int32).)
Public methodGetOrdinalGets the column ordinal, given the name of the column. (Overrides DbDataReader.GetOrdinal(String).)
Public methodGetProviderSpecificFieldTypeReturns the provider-specific field type of the specified column. (Inherited from DbDataReader.)
Public methodGetProviderSpecificValueGets the value of the specified column as an instance of Object. (Inherited from DbDataReader.)
Public methodGetProviderSpecificValuesGets all provider-specific attribute columns in the collection for the current row. (Inherited from DbDataReader.)
Public methodGetSchemaTableReturns a DataTable that describes the column metadata of the OdbcDataReader. (Overrides DbDataReader.GetSchemaTable().)
Public methodGetStringGets the value of the specified column as a String. (Overrides DbDataReader.GetString(Int32).)
Public methodGetTimeGets the value of the specified column as a TimeSpan object.
Public methodGetTypeGets the Type of the current instance. (Inherited from Object.)
Public methodGetValueGets the value of the column at the specified ordinal in its native format. (Overrides DbDataReader.GetValue(Int32).)
Public methodGetValuesPopulates an array of objects with the column values of the current row. (Overrides DbDataReader.GetValues(Object[]).)
Public methodInitializeLifetimeServiceObtains a lifetime service object to control the lifetime policy for this instance. (Inherited from MarshalByRefObject.)
Public methodIsDBNullGets a value that indicates whether the column contains nonexistent or missing values. (Overrides DbDataReader.IsDBNull(Int32).)
Protected methodMemberwiseClone()Creates a shallow copy of the current Object. (Inherited from Object.)
Protected methodMemberwiseClone(Boolean)Creates a shallow copy of the current MarshalByRefObject object. (Inherited from MarshalByRefObject.)
Public methodNextResultAdvances the OdbcDataReader to the next result when reading the results of batch SQL statements. (Overrides DbDataReader.NextResult().)
Public methodReadAdvances the OdbcDataReader to the next record. (Overrides DbDataReader.Read().)
Public methodToStringReturns a string that represents the current object. (Inherited from Object.)
Top

  NameDescription
Explicit interface implemetationPrivate methodIDataRecord.GetDataFor a description of this member, see IDataRecord.GetData. (Inherited from DbDataReader.)
Top

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.

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();
    }
}


.NET Framework

Supported in: 4, 3.5, 3.0, 2.0, 1.1

.NET Framework Client Profile

Supported in: 4, 3.5 SP1

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

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

Community Additions

ADD
Show:
© 2014 Microsoft