How to ADO.NET OleDbDataReader
The OleDbDataReader Object in ADO.NET offers a connection-oriented data access to OLEDB data sources. When the ExecuteReader() method is invoked in the OleDbCommand Object, it sends the SQL statements to the OleDbConnection Object and generates an OleDbDataReader Object based on the provided SQL statement. As a result of executing the ExecuteReader() method in the OleDbCommand Object, an instance of the OleDbDataReader Object, specifically from the OleDb namespace, is instantiated.
In order to retrieve data from an OleDbDataReader, it is essential for the reader to be open and positioned prior to the first record. This means that before accessing any data values, it is necessary to call the Read() method on the OleDbDataReader Object to advance to the initial row.
The Read() method in the OleDbDataReader Object is utilized to traverse the rows of data within the OleDbDataReader. Each invocation of the Read() method moves the reader forward to the next valid row, if any rows exist. In this manner, the Read() method enables sequential traversal through the result set, continually progressing to a new valid row until there are no more rows to retrieve.
Consequently, the Read() method is typically employed within a loop construct to iterate through the OleDbDataReader and access the data from each row. Each iteration of the Read() method advances the OleDbDataReader Object to the subsequent row, facilitating the retrieval of data values using the appropriate GetXXX methods, where XXX represents the data type of the column.
It is important to emphasize that the Read() method of the OleDbDataReader Object exclusively moves forward to the next valid row in the result set. It does not allow for backward movement or repositioning to a previous row. Thus, the Read() method is designed to be utilized in a forward-only manner, reading rows sequentially.Full Source VB.NET
The ExecuteReader() method in the OleDbCommand Object serves as the mechanism for generating an OleDbDataReader Object, enabling connection-oriented data access to OLEDB data sources. By utilizing the Read() method, the OleDbDataReader Object can be navigated row by row, progressively advancing to new valid rows, if available, in order to read and retrieve data from the OleDbDataReader.