OdbcDataReader Class
Definition
Important
Some information relates to prerelease product that may be substantially modified before it’s released. Microsoft makes no warranties, express or implied, with respect to the information provided here.
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 ref class OdbcDataReader sealed : MarshalByRefObject, IDisposable, System::Collections::IEnumerable, System::Data::IDataReader
public sealed class OdbcDataReader : System.Data.Common.DbDataReader
public sealed class OdbcDataReader : MarshalByRefObject, IDisposable, System.Collections.IEnumerable, System.Data.IDataReader
type OdbcDataReader = class
inherit DbDataReader
type OdbcDataReader = class
inherit MarshalByRefObject
interface IDataReader
interface IDataRecord
interface IDisposable
interface IEnumerable
Public NotInheritable Class OdbcDataReader
Inherits DbDataReader
Public NotInheritable Class OdbcDataReader
Inherits MarshalByRefObject
Implements IDataReader, IDisposable, IEnumerable
- Inheritance
- Inheritance
- Implements
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 |
Gets a value that indicates the depth of nesting for the current row. |
FieldCount |
Gets the number of columns in the current row. |
HasRows |
Gets a value that indicates whether the OdbcDataReader contains one or more rows. |
IsClosed |
Indicates whether the OdbcDataReader is closed. |
Item[Int32] |
Gets the value of the specified column in its native format given the column ordinal. |
Item[String] |
Gets the value of the specified column in its native format given the column name. |
RecordsAffected |
Gets the number of rows changed, inserted, or deleted by execution of the SQL statement. |
VisibleFieldCount |
Gets the number of fields in the DbDataReader that are not hidden. (Inherited from DbDataReader) |
Methods
Close() |
Closes the OdbcDataReader object. |
CloseAsync() |
Asynchronously closes the DbDataReader object. (Inherited from DbDataReader) |
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) |
Dispose() |
Releases all resources used by the current instance of the DbDataReader class. (Inherited from DbDataReader) |
Dispose(Boolean) |
Releases the unmanaged resources used by the DbDataReader and optionally releases the managed resources. (Inherited from DbDataReader) |
DisposeAsync() |
Asynchronously releases all resources used by the current instance of the DbDataReader class. (Inherited from DbDataReader) |
Equals(Object) |
Determines whether the specified object is equal to the current object. (Inherited from Object) |
Finalize() |
Allows the object to try to free resources and perform other cleanup operations before it is reclaimed by garbage collection. |
GetBoolean(Int32) |
Gets the value of the specified column as a Boolean. |
GetByte(Int32) |
Gets the value of the specified column as a byte. |
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) |
Gets the value of the specified column as a character. |
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. |
GetColumnSchemaAsync(CancellationToken) |
This is the asynchronous version of GetColumnSchema(DbDataReader).
Providers should override with an appropriate implementation.
The |
GetData(Int32) |
Returns an IDataReader for the specified column ordinal. |
GetData(Int32) |
Returns a nested data reader for the requested column. (Inherited from DbDataReader) |
GetDataTypeName(Int32) |
Gets the name of the source data type. |
GetDate(Int32) |
Gets the value of the specified column as a DateTime object. |
GetDateTime(Int32) |
Gets the value of the specified column as a DateTime object. |
GetDbDataReader(Int32) |
Returns a DbDataReader object for the requested column ordinal that can be overridden with a provider-specific implementation. (Inherited from DbDataReader) |
GetDecimal(Int32) |
Gets the value of the specified column as a Decimal object. |
GetDouble(Int32) |
Gets the value of the specified column as a double-precision floating-point number. |
GetEnumerator() |
Returns an IEnumerator that can be used to iterate through the rows in the data reader. |
GetFieldType(Int32) |
Gets the Type that is the data type of the object. |
GetFieldValue<T>(Int32) |
Gets the value of the specified column as the requested type. (Inherited from DbDataReader) |
GetFieldValueAsync<T>(Int32, CancellationToken) |
Asynchronously gets the value of the specified column as the requested type. (Inherited from DbDataReader) |
GetFieldValueAsync<T>(Int32) |
Asynchronously gets the value of the specified column as the requested type. (Inherited from DbDataReader) |
GetFloat(Int32) |
Gets the value of the specified column as a single-precision floating-point number. |
GetGuid(Int32) |
Gets the value of the specified column as a globally unique identifier (GUID). |
GetHashCode() |
Serves as the default hash function. (Inherited from Object) |
GetInt16(Int32) |
Gets the value of the specified column as a 16-bit signed integer. |
GetInt32(Int32) |
Gets the value of the specified column as a 32-bit signed integer. |
GetInt64(Int32) |
Gets the value of the specified column as a 64-bit signed integer. |
GetLifetimeService() |
Obsolete.
Retrieves the current lifetime service object that controls the lifetime policy for this instance. (Inherited from MarshalByRefObject) |
GetName(Int32) |
Gets the name of the specified column. |
GetOrdinal(String) |
Gets the column ordinal, given the name of the column. |
GetProviderSpecificFieldType(Int32) |
Gets the provider-specific type of the specified column. (Inherited from DbDataReader) |
GetProviderSpecificValue(Int32) |
Gets the value of the specified column as an instance of a provider-specific type. (Inherited from DbDataReader) |
GetProviderSpecificValues(Object[]) |
Gets all provider-specific attribute columns in the collection for the current row. (Inherited from DbDataReader) |
GetSchemaTable() |
Returns a DataTable that describes the column metadata of the OdbcDataReader. |
GetSchemaTableAsync(CancellationToken) |
This is the asynchronous version of GetSchemaTable().
Providers should override with an appropriate implementation.
The |
GetStream(Int32) |
Gets a stream to retrieve data from the specified column. (Inherited from DbDataReader) |
GetString(Int32) |
Gets the value of the specified column as a String. |
GetTextReader(Int32) |
Gets a text reader to retrieve data from the column. (Inherited from DbDataReader) |
GetTime(Int32) |
Gets the value of the specified column as a TimeSpan object. |
GetType() |
Gets the Type of the current instance. (Inherited from Object) |
GetValue(Int32) |
Gets the value of the column at the specified ordinal in its native format. |
GetValues(Object[]) |
Populates an array of objects with the column values of the current row. |
InitializeLifetimeService() |
Obsolete.
Obtains a lifetime service object to control the lifetime policy for this instance. (Inherited from MarshalByRefObject) |
IsDBNull(Int32) |
Gets a value that indicates whether the column contains nonexistent or missing values. |
IsDBNullAsync(Int32, CancellationToken) |
Asynchronously gets a value that indicates whether the column contains non-existent or missing values. (Inherited from DbDataReader) |
IsDBNullAsync(Int32) |
Asynchronously gets a value that indicates whether the column contains non-existent or missing values. (Inherited from DbDataReader) |
MemberwiseClone() |
Creates a shallow copy of the current Object. (Inherited from Object) |
MemberwiseClone(Boolean) |
Creates a shallow copy of the current MarshalByRefObject object. (Inherited from MarshalByRefObject) |
NextResult() |
Advances the OdbcDataReader to the next result when reading the results of batch SQL statements. |
NextResultAsync() |
Asynchronously advances the reader to the next result when reading the results of a batch of statements. (Inherited from DbDataReader) |
NextResultAsync(CancellationToken) |
Asynchronously advances the reader to the next result when reading the results of a batch of statements. (Inherited from DbDataReader) |
Read() |
Advances the OdbcDataReader to the next record. |
ReadAsync() |
Asynchronously advances the reader to the next record in a result set. (Inherited from DbDataReader) |
ReadAsync(CancellationToken) |
Asynchronously advances the reader to the next record in a result set. (Inherited from DbDataReader) |
ToString() |
Returns a string that represents the current object. (Inherited from Object) |
Explicit Interface Implementations
IDataRecord.GetData(Int32) |
For a description of this member, see GetData(Int32). (Inherited from DbDataReader) |
IDisposable.Dispose() |
This API supports the product infrastructure and is not intended to be used directly from your code. Releases all resources used by the current instance of the OdbcDataReader class. |
IEnumerable.GetEnumerator() |
This API supports the product infrastructure and is not intended to be used directly from your code. Returns an enumerator that iterates through a collection. |
Extension Methods
CanGetColumnSchema(DbDataReader) |
Gets a value that indicates whether a DbDataReader can get a column schema. |
GetColumnSchema(DbDataReader) |
Gets the column schema (DbColumn collection) for a DbDataReader. |
GetBoolean(DbDataReader, String) |
Gets the value of the specified column as a Boolean. |
GetByte(DbDataReader, String) |
Gets the value of the specified column as a byte. |
GetBytes(DbDataReader, String, Int64, Byte[], Int32, Int32) |
Reads a specified number of bytes from the specified column starting at a specified index and writes them to a buffer starting at a specified position in the buffer. |
GetChar(DbDataReader, String) |
Gets the value of the specified column as a single character. |
GetChars(DbDataReader, String, Int64, Char[], Int32, Int32) |
Reads a specified number of characters from a specified column starting at a specified index, and writes them to a buffer starting at a specified position. |
GetData(DbDataReader, String) |
Returns a nested data reader for the requested column. |
GetDataTypeName(DbDataReader, String) |
Gets name of the data type of the specified column. |
GetDateTime(DbDataReader, String) |
Gets the value of the specified column as a DateTime object. |
GetDecimal(DbDataReader, String) |
Gets the value of the specified column as a Decimal. |
GetDouble(DbDataReader, String) |
Gets the value of the specified column as a double-precision floating point number. |
GetFieldType(DbDataReader, String) |
Gets the data type of the specified column. |
GetFieldValue<T>(DbDataReader, String) |
Gets the value of the specified column as the requested type. |
GetFieldValueAsync<T>(DbDataReader, String, CancellationToken) |
Asynchronously gets the value of the specified column as the requested type. |
GetFloat(DbDataReader, String) |
Gets the value of the specified column as a single-precision floating point number. |
GetGuid(DbDataReader, String) |
Gets the value of the specified column as a globally unique identifier (GUID). |
GetInt16(DbDataReader, String) |
Gets the value of the specified column as a 16-bit signed integer. |
GetInt32(DbDataReader, String) |
Gets the value of the specified column as a 32-bit signed integer. |
GetInt64(DbDataReader, String) |
Gets the value of the specified column as a 64-bit signed integer. |
GetProviderSpecificFieldType(DbDataReader, String) |
Gets the provider-specific type of the specified column. |
GetProviderSpecificValue(DbDataReader, String) |
Gets the value of the specified column as an instance of a provider-specific type. |
GetStream(DbDataReader, String) |
Gets a stream to retrieve data from the specified column. |
GetString(DbDataReader, String) |
Gets the value of the specified column as an instance of String. |
GetTextReader(DbDataReader, String) |
Gets a text reader to retrieve data from the column. |
GetValue(DbDataReader, String) |
Gets the value of the specified column as an instance of Object. |
IsDBNull(DbDataReader, String) |
Gets a value that indicates whether the column contains nonexistent or missing values. |
IsDBNullAsync(DbDataReader, String, CancellationToken) |
Asynchronously gets a value that indicates whether the column contains non-existent or missing values. |
Cast<TResult>(IEnumerable) |
Casts the elements of an IEnumerable to the specified type. |
OfType<TResult>(IEnumerable) |
Filters the elements of an IEnumerable based on a specified type. |
AsParallel(IEnumerable) |
Enables parallelization of a query. |
AsQueryable(IEnumerable) |
Converts an IEnumerable to an IQueryable. |
ConfigureAwait(IAsyncDisposable, Boolean) |
Configures how awaits on the tasks returned from an async disposable will be performed. |