Documentation Navigation

ODBC Data Reader (System.Data.OdbcClient.OdbcDataReader)

Represents a data reader for the ODBC Data Provider that reads rows from a data source.

Remarks

The OdbcDataReader provides a way to retrieve a forward-only stream of data rows from an ODBC data source. It is optimized for performance, and you should close the reader as soon as you are finished with it.

Note: This class is part of the System.Data.OdbcClient namespace, which requires the installation of the .NET Framework Data Provider for ODBC.

Syntax

public sealed class OdbcDataReader : DbDataReader, IDataRecord, IEnumerable, IEnumerable<DbDataRecord>

Inheritance Hierarchy

System.Data.Common.DbDataReader > System.Data.Common.DataReader > System.Data.Common.IDbAbstractDataReader > System.Data.IDataRecord > System.Collections.IEnumerable > System.Collections.Generic.IEnumerable<T>

Members

Properties

Name Description
HasRows Gets a value indicating whether the data reader contains one or more rows.
FieldCount Gets the number of columns in the current row.
Depth Gets the depth of the current row in the result set.
IsClosed Gets a value indicating whether the data reader has been closed.

Methods

Name Description
GetValues(object[] values) Reads a set of column values from the current row and advances the data reader to the next row.
GetString(int ordinal) Gets the value of the specified column as a string.
GetInt32(int ordinal) Gets the value of the specified column as a 32-bit signed integer.
GetDateTime(int ordinal) Gets the value of the specified column as a DateTime object.
GetDecimal(int ordinal) Gets the value of the specified column as a decimal.
GetDouble(int ordinal) Gets the value of the specified column as a double-precision floating-point number.
GetGuid(int ordinal) Gets the value of the specified column as a GUID.
GetInt64(int ordinal) Gets the value of the specified column as a 64-bit signed integer.
GetBoolean(int ordinal) Gets the value of the specified column as a boolean.
GetByte(int ordinal) Gets the value of the specified column as a byte.
GetBytes(int ordinal, long dataOffset, byte[] buffer, int bufferOffset, int length) Reads a stream of bytes from the specified column offset into the buffer as an array of bytes.
GetChar(int ordinal) Gets the value of the specified column as a character.
GetChars(int ordinal, long dataOffset, char[] buffer, int bufferOffset, int length) Reads a stream of characters from the specified column offset into the buffer as an array of characters.
GetFloat(int ordinal) Gets the value of the specified column as a single-precision floating-point number.
GetOrdinal(string name) Gets the column ordinal for the specified column name.
GetOdbcValues(object[] values) Populates an array of objects with the values of the columns of the current row.
GetOdbcInt32(int ordinal) Gets the value of the specified column as an OdbcInt32.
GetValue(int ordinal) Gets the value of the specified column.
GetData(int ordinal) Returns an IDataRecord that represents an IDataReader.
Read() Advances the OdbcDataReader to the next record.
Close() Closes the OdbcDataReader object.
Dispose() Releases the resources used by the OdbcDataReader.

See Also

System.Data.OdbcClient Namespace
OdbcCommand
OdbcConnection

Tip: Always call the Close() method when you are finished with the OdbcDataReader to release resources. Using a using statement is recommended for proper disposal.

HasRows Property

public override bool HasRows { get; }

Gets a value indicating whether the data reader contains one or more rows.

FieldCount Property

public override int FieldCount { get; }

Gets the number of columns in the current row.

Depth Property

public override int Depth { get; }

Gets the depth of the current row in the result set. This is typically 0 for a single result set.

IsClosed Property

public override bool IsClosed { get; }

Gets a value indicating whether the data reader has been closed.

GetValues Method

public override int GetValues(object[] values);

Parameters

  • values: An array of object to copy the column values into.

Returns

  • The number of object instances copied into the array.

Reads a set of column values from the current row and advances the data reader to the next row.

GetString Method

public string GetString(int ordinal);

Parameters

  • ordinal: The zero-based column ordinal of the column to get.

Returns

  • The value of the specified column as a string.

Gets the value of the specified column as a string.

GetInt32 Method

public int GetInt32(int ordinal);

Parameters

  • ordinal: The zero-based column ordinal of the column to get.

Returns

  • The value of the specified column as a 32-bit signed integer.

Gets the value of the specified column as a 32-bit signed integer.

GetDateTime Method

public DateTime GetDateTime(int ordinal);

Parameters

  • ordinal: The zero-based column ordinal of the column to get.

Returns

  • The value of the specified column as a DateTime object.

Gets the value of the specified column as a DateTime object.

GetDecimal Method

public decimal GetDecimal(int ordinal);

Parameters

  • ordinal: The zero-based column ordinal of the column to get.

Returns

  • The value of the specified column as a decimal.

Gets the value of the specified column as a decimal.

GetDouble Method

public double GetDouble(int ordinal);

Parameters

  • ordinal: The zero-based column ordinal of the column to get.

Returns

  • The value of the specified column as a double-precision floating-point number.

Gets the value of the specified column as a double-precision floating-point number.

GetGuid Method

public Guid GetGuid(int ordinal);

Parameters

  • ordinal: The zero-based column ordinal of the column to get.

Returns

  • The value of the specified column as a GUID.

Gets the value of the specified column as a GUID.

GetInt64 Method

public long GetInt64(int ordinal);

Parameters

  • ordinal: The zero-based column ordinal of the column to get.

Returns

  • The value of the specified column as a 64-bit signed integer.

Gets the value of the specified column as a 64-bit signed integer.

GetBoolean Method

public bool GetBoolean(int ordinal);

Parameters

  • ordinal: The zero-based column ordinal of the column to get.

Returns

  • The value of the specified column as a boolean.

Gets the value of the specified column as a boolean.

GetByte Method

public byte GetByte(int ordinal);

Parameters

  • ordinal: The zero-based column ordinal of the column to get.

Returns

  • The value of the specified column as a byte.

Gets the value of the specified column as a byte.

GetBytes Method

public override long GetBytes(int ordinal, long dataOffset, byte[] buffer, int bufferOffset, int length);

Parameters

  • ordinal: The zero-based column ordinal of the column to read.
  • dataOffset: The zero-based offset in the data field from which to begin the read operation.
  • buffer: The buffer into which to copy the data.
  • bufferOffset: The zero-based offset in the buffer to begin writing data.
  • length: The maximum number of bytes to read.

Returns

  • The actual number of bytes read into the buffer.

Reads a stream of bytes from the specified column offset into the buffer as an array of bytes.

GetChar Method

public char GetChar(int ordinal);

Parameters

  • ordinal: The zero-based column ordinal of the column to get.

Returns

  • The value of the specified column as a character.

Gets the value of the specified column as a character.

GetChars Method

public override long GetChars(int ordinal, long dataOffset, char[] buffer, int bufferOffset, int length);

Parameters

  • ordinal: The zero-based column ordinal of the column to read.
  • dataOffset: The zero-based offset in the data field from which to begin the read operation.
  • buffer: The buffer into which to copy the data.
  • bufferOffset: The zero-based offset in the buffer to begin writing data.
  • length: The maximum number of characters to read.

Returns

  • The actual number of characters read into the buffer.

Reads a stream of characters from the specified column offset into the buffer as an array of characters.

GetFloat Method

public float GetFloat(int ordinal);

Parameters

  • ordinal: The zero-based column ordinal of the column to get.

Returns

  • The value of the specified column as a single-precision floating-point number.

Gets the value of the specified column as a single-precision floating-point number.

GetOrdinal Method

public override int GetOrdinal(string name);

Parameters

  • name: The name of the column to find.

Returns

  • The zero-based column ordinal for the specified column name.

Gets the column ordinal for the specified column name.

GetOdbcValues Method

public int GetOdbcValues(object[] values);

Parameters

  • values: An array of object to copy the column values into.

Returns

  • The number of object instances copied into the array.

Populates an array of objects with the values of the columns of the current row.

GetOdbcInt32 Method

public OdbcInt32 GetOdbcInt32(int ordinal);

Parameters

  • ordinal: The zero-based column ordinal of the column to get.

Returns

  • An OdbcInt32 object representing the value of the specified column.

Gets the value of the specified column as an OdbcInt32.

GetValue Method

public override object GetValue(int ordinal);

Parameters

  • ordinal: The zero-based column ordinal of the column to get.

Returns

  • The value of the specified column.

Gets the value of the specified column.

GetData Method

public override IDataReader GetData(int ordinal);

Parameters

  • ordinal: The zero-based column ordinal of the column to retrieve.

Returns

Returns an IDataRecord that represents an IDataReader.

Read Method

public override bool Read();

Returns

  • true if there are more rows; otherwise, false.

Advances the OdbcDataReader to the next record.

Close Method

public override void Close();

Closes the OdbcDataReader object.

Dispose Method

protected virtual void Dispose(bool disposing);

Releases the resources used by the OdbcDataReader. This method is called by the Dispose() method.

public void Dispose();

Releases all resources used by the ODBC Data Reader.