OleDbDataReader
Class
Definition
Provides a way of reading a forward-only stream of data rows from a data source. This class cannot be inherited.
public sealed class OleDbDataReader : System.Data.Common.DbDataReader
- Inheritance
Inherited Members
System.Data.Common.DbDataReader
System.MarshalByRefObject
System.Object
Examples
The following example creates an OleDbConnection, an OleDbCommand, and an OleDbDataReader. The example reads through the data, writing it out to the console. Finally, the example closes the OleDbDataReader and then the OleDbConnection.
public static void ReadData(string connectionString, string queryString)
{
using (OleDbConnection connection = new OleDbConnection(connectionString))
{
OleDbCommand command = new OleDbCommand(queryString, connection);
connection.Open();
OleDbDataReader reader = command.ExecuteReader();
while (reader.Read())
{
Console.WriteLine(reader[0].ToString());
}
reader.Close();
}
}
Public Sub ReadData(ByVal connectionString As String, _
ByVal queryString As String)
Using connection As New OleDbConnection(connectionString)
Dim command As New OleDbCommand(queryString, connection)
connection.Open()
Dim reader As OleDbDataReader = command.ExecuteReader()
While reader.Read()
Console.WriteLine(reader(0).ToString())
End While
reader.Close()
End Using
End Sub
Remarks
To create an OleDbDataReader, you must call the ExecuteReader method of the OleDbCommand object, instead of directly using a constructor.
Before you close the OleDbConnection, first close the OleDbDataReader object. You must also close the OleDbDataReader object if you plan to resuse an OleDbCommand object.For example, you cannot retrieve output parameters until after you call Close.
Changes made to a result set by another process or thread while data is being read may be visible to the user of the OleDbDataReader. However, the precise behavior is timing dependent.
IsClosed and RecordsAffected are the only properties that you can call after the OleDbDataReader is closed. Although the RecordsAffected property may be accessed while the OleDbDataReader exists, always call Close before returning the value of RecordsAffected to guarantee an accurate return value.
Properties
| Depth |
Gets a value that indicates the depth of nesting for the current row. |
| FieldCount |
Gets the number of columns in the current row. |
| HasRows |
Gets a value that indicates whether the OleDbDataReader contains one or more rows. |
| IsClosed |
Indicates whether the data reader is closed. |
| Item[Int32] |
Gets the value of the specified column in its native format given the column ordinal. |
| Item[String] |
Gets the value of the specified column in its native format given the column name. |
| RecordsAffected |
Gets the number of rows changed, inserted, or deleted by execution of the SQL statement. |
| VisibleFieldCount |
Gets the number of fields in the OleDbDataReader that are not hidden. |
Methods
| Close() |
Closes the OleDbDataReader object. |
| GetBoolean(Int32) |
Gets the value of the specified column as a Boolean. |
| GetByte(Int32) |
Gets the value of the specified column as a byte. |
| GetBytes(Int32, Int64, Byte[], Int32, Int32) |
Reads a stream of bytes from the specified column offset into the buffer as an array starting at the given buffer offset. |
| GetChar(Int32) |
Gets the value of the specified column as a character. |
| GetChars(Int32, Int64, Char[], Int32, Int32) |
Reads a stream of characters from the specified column offset into the buffer as an array starting at the given buffer offset. |
| GetData(Int32) |
Returns an OleDbDataReader object for the requested column ordinal. |
| GetDataTypeName(Int32) |
Gets the name of the source data type. |
| GetDateTime(Int32) |
Gets the value of the specified column as a DateTime object. |
| GetDecimal(Int32) |
Gets the value of the specified column as a Decimal object. |
| GetDouble(Int32) |
Gets the value of the specified column as a double-precision floating-point number. |
| GetEnumerator() |
Returns an IEnumerator that can be used to iterate through the rows in the data reader. |
| GetFieldType(Int32) |
Gets the Type that is the data type of the object. |
| GetFloat(Int32) |
Gets the value of the specified column as a single-precision floating-point number. |
| GetGuid(Int32) |
Gets the value of the specified column as a globally unique identifier (GUID). |
| GetInt16(Int32) |
Gets the value of the specified column as a 16-bit signed integer. |
| GetInt32(Int32) |
Gets the value of the specified column as a 32-bit signed integer. |
| GetInt64(Int32) |
Gets the value of the specified column as a 64-bit signed integer. |
| GetName(Int32) |
Gets the name of the specified column. |
| GetOrdinal(String) |
Gets the column ordinal, given the name of the column. |
| GetSchemaTable() |
Returns a DataTable that describes the column metadata of the OleDbDataReader. |
| GetString(Int32) |
Gets the value of the specified column as a string. |
| GetTimeSpan(Int32) |
Gets the value of the specified column as a TimeSpan object. |
| GetValue(Int32) |
Gets the value of the column at the specified ordinal in its native format. |
| GetValues(Object[]) |
Populates an array of objects with the column values of the current row. |
| IsDBNull(Int32) |
Gets a value that indicates whether the column contains nonexistent or missing values. |
| NextResult() |
Advances the data reader to the next result, when reading the results of batch SQL statements. |
| Read() |
Advances the OleDbDataReader to the next record. |
Extension Methods
| Cast<TResult>(IEnumerable) | |
| OfType<TResult>(IEnumerable) | |
| AsParallel(IEnumerable) | |
| AsQueryable(IEnumerable) |