C# ADO.NET OleDbDataReader
The OleDbDataReader Object in C# provides a connection-oriented data access to OLEDB Data Sources through C# applications.
ExecuteReader() method
To retrieve data using the OleDbDataReader, you typically use the ExecuteReader() method in the OleDbCommand Object. This method sends the SQL statements or Stored Procedures to the associated OleDbConnection Object and populates an OleDbDataReader Object based on the executed SQL statement.
When the ExecuteReader method is executed on the OleDbCommand Object, it instantiates an OleDb.OleDbDataReader Object. This OleDbDataReader Object serves as a cursor that allows you to efficiently read and access the retrieved data.
Before reading from the OleDbDataReader, it's important to ensure that the OleDbDataReader is open and positioned prior to the first record. You can achieve this by invoking the Read() method, which advances the OleDbDataReader to the next row and returns a boolean value indicating whether there are more rows available.
Read() method
The Read() method of the OleDbDataReader is used to sequentially read the rows from the OleDbDataReader. It always moves the cursor forward to the next valid row, if any rows exist.
By invoking the Read() method in a loop, you can retrieve the data from each row and access the values of individual columns using the appropriate getter methods (e.g., GetString(), GetInt32(), etc.) based on the data type.
Full Source C#Conclusion
The OleDbDataReader Object in C# enables connection-oriented data access to OLEDB Data Sources. It is instantiated using the ExecuteReader() method in the OleDbCommand Object and provides methods like Read() to sequentially retrieve and access data rows. Ensuring the OleDbDataReader is open and positioned correctly before reading is essential, and proper management of the connection and closing of the OleDbDataReader and OleDbConnection is necessary when done reading the data.
- C# ADO.NET Command
- C# ADO.NET SqlCommand - ExecuteNonQuery
- C# ADO.NET OleDbCommand - ExecuteNonQuery
- C# ADO.NET SqlCommand - ExecuteScalar
- C# ADO.NET OleDbCommand - ExecuteScalar
- C# ADO.NET SqlCommand - ExecuteReader
- C# ADO.NET OleDbCommand - ExecuteReader
- C# ADO.NET DataReader
- C# ADO.NET SqlDataReader
- C# Multiple Result Sets
- C# Table Schema from SqlDataReader
- C# Table Schema from OleDbDataReader
- C# ADO.NET DataAdapter
- C# ADO.NET SqlDataAdapter
- C# ADO.NET OleDbDataAdapter
- C# ExecuteReader and ExecuteNonQuery
- System.Data.SqlClient.SqlException: Login failed for user