The ADO.Net DataReader
The Data Reader is a simple object – a use one time and throw away container for holding the results of an ExecuteReade()r method of the command object. The Data Reader’s principal method is the Read() method, which reads one record from the result set.
Since in a client server environment, it is considered good programming practice to be frugal in retrieving records, the DataReader at any one time will contain relatively small amounts of data. For instance, in a typical form procedure, the trip to the server may only return a single record, or perhaps a single record with associated child records needed to populate one screen.
When multiple records are retrieved, they are read from the data reader in loop structure one record at a time.
Each record is processed and/or stored in turn, because the DataReader has ho no capacity for returning to any record after the application has passed it. The only way to revisit a record in the DataReader is to re-connect and request the data again.
In more sophisticated applications, the DataReader may contain multiple records which may be read and mapped into a DataGrid. The Grid may be equipped with edit, append and delete buttons to allow changing of the data and eventual uploading of the changed results back to the server through the command object. It is also possible to use the GetSchemaTable() method to acquire characteristics of the data columns and built a local DataTable on the client – either virtually or in an auxiliary Access, or XML table. The System.Data.DataTable() method is used to built the structure. A key property is the Item property, which will allow you to get field names like the fields collection in a DAO recordset.
It is also possible to retrieve multiple resultsets at the same time into a DataReader. This is frequently the result of a batch SQL Server stored procedure with multiple SELECT statements. The NextResult method allows you to advance to the next recordset within the DataReader.
Do while dr.NextResult
Do while dr.Read
Process stuff s
• Information on .Net Resources
This is an excellent resource that links you to comprehensive resources on .Net.
• Article on Microsoft .Net
This resource provides a comprehensive information on Microsoft .Net
About the Author: Chris Kemp is a well knoen author who writes best quality articles on IT, Software, Programming, etc. For further details please visit the site www.paladn.com