Viewing Data

An efficient means of viewing database information is through an ADO.NET DataReader, which is used to obtain a forward-only, read-only data stream from a database. A DataReader may not be written to or modified. This is a very efficient means of obtaining data when the only action required is to view information. There are three steps to create a DataReader:

Create a command object from the connection object.
Specify what the command object should do by initializing its CommandText property.
Create a reader based upon the command object.

The following example shows how to create an OleDbDataReader, the DataReader belonging to the OLE DB data provider.

 OleDbDataReader dbReader = null; OleDbCommand cmd = conn.CreateCommand(); ...

Get C# Unleashed now with the O’Reilly learning platform.

O’Reilly members experience live online training, plus books, videos, and digital content from nearly 200 publishers.