OdbcDataReader Class
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 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(); } }
System.MarshalByRefObject
System.Data.Common.DbDataReader
System.Data.Odbc.OdbcDataReader
Windows 98, Windows Server 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 Microsoft .NET Framework 3.0 is supported on Windows Vista, Microsoft Windows XP SP2, and Windows Server 2003 SP1.