Traversing a Data Reader
As mentioned yesterday in discussing the command object, the ExecuteReader method is used to create a data reader object that can then be traversed. Before calling the method, the command must be associated with a connection object and the connection opened using its Open method.
After the data reader has been opened, it can be traversed using its Read method. The Read method positions the data reader at the next available row and so must be called prior to reading data from the first row. In the process, the Read method returns True if more rows are available and False after all the rows have been read. When the data reader is exhausted, the Close method of the data reader and the connection should be called to ensure ...
Get Sams Teach Yourself ADO.NET in 21 Days 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.