Working with the SqlDataReader

The SqlCommand class is designed to help you construct your queries. As shown earlier in the chapter, calling the ExecuteReader method on a SqlCommand object returns a SqlDataReader object, which you can use to retrieve the rows returned by those queries.

The SqlDataReader class is similar to other reader classes in the .NET Framework, such as the XmlReader, TextReader, and StreamReader classes. Each of these classes provides an efficient, lightweight object that lets you examine (in a read-only fashion) the data that the object exposes. The TextReader class, for example, has methods that let you read the contents of a text file one line at a time. Similarly, the SqlDataReader exposes properties and methods that let ...

Get Programming Microsoft® ADO.NET 2.0 Core Reference, 2nd Edition now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.