OdbcDataReader Class
Provides a way of reading a forward-only stream of data rows from a data source. This class cannot be inherited.
Assembly: System.Data (in System.Data.dll)
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 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
System.MarshalByRefObject
System.Data.Common.DbDataReader
System.Data.Odbc.OdbcDataReader
Windows 7, Windows Vista, Windows XP SP2, Windows XP Media Center Edition, Windows XP Professional x64 Edition, Windows XP Starter Edition, Windows Server 2008 R2, Windows Server 2008, Windows Server 2003, Windows Server 2000 SP4, Windows Millennium Edition, Windows 98
The .NET Framework and .NET Compact Framework do not support all versions of every platform. For a list of the supported versions, see .NET Framework System Requirements.