Skip Headers

Oracle Data Provider for .NET Developer's Guide
Release 9.2.0.2

Part Number A96160-01
Go To Table Of Contents
Contents
Go To Index
Index

Go to previous page Go to beginning of chapter Go to next page

Oracle.DataAccess.Client Namespace, 6 of 26


OracleDataReader Class

An OracleDataReader object represents a forward-only, read-only, in-memory result set.

Unlike the DataSet, the OracleDataReader stays connected and fetches one row at a time.

See Also:

Class Inheritance

Object

  MarshalByRefObject

    OracleDataReader

Declaration
// C#
public sealed class OracleDataReader : MarshalByRefObject, IEnumerable,  
  IDataReader, IDisposable, IDataRecord
Thread Safety

All public static methods are thread-safe, although instance methods do not guarantee thread safety.

Remarks

An OracleDataReader instance is constructed by a call to the ExecuteReader method of the OracleCommand object. The only properties that can be accessed after the DataReader is closed or has been disposed, are IsClosed and RecordsAffected.

Example

The OracleDataReader examples in this section are based on the EMPINFO table which is defined as follows:


  CREATE TABLE empInfo (
    empno NUMBER(4) PRIMARY KEY,
    empName VARCHAR2(20) NOT NULL,
    hiredate DATE,
    salary NUMBER(7,2),
    jobDescription Clob,
    byteCodes BLOB
);

The EMPINFO table has the following values:


EMPNO    EMPNAME    HIREDATE    SALARY     JOBDESCRIPTION  BYTECODES 
                                                           (Hex Values)
=====    =======    ========    ======     ==============  ============

    1    KING       01-MAY-81   12345.67   SOFTWARE ENGR   {0x12, 0x34}
    2    SCOTT      01-SEP-75   34567.89   MANAGER         {0x56, 0x78}
    3    BLAKE      01-OCT-90   9999.12    TRANSPORT       {0x23, 0x45}
    4    SMITH      NULL        NULL       NULL             NULL

The following example retrieves the data from the EMPINFO table:

//C #
//This method retrieves all the data from EMPINFO table

public void ReadEmpInfo(string connStr)
{
   string cmdStr = "SELECT * FROM EMPINFO";
   OracleConnection connection = new OracleConnection(connStr);
   OracleCommand cmd = new OracleCommand(cmdStr, connection);
   connection.Open();

   OracleDataReader reader = cmd.ExecuteReader();

   //declare the variables to retrieve the data in EmpInfo
   short empNo;
   string empName;
   DateTime hireDate;
   double salary;
   string jobDesc;
   byte[] byteCodes = new byte[10];

   //read the next row until end of row
   while (reader.Read())
     {
       empNo = reader.GetInt16(0);
       Console.WriteLine("Employee number: " + empNo);

       empName = reader.GetString(1);
       Console.WriteLine("Employee name: " + empName);

       //the following columns can have NULL value, so it
       //is important to call IsDBNull before getting the column data
     if (!reader.IsDBNull(2))
     {
       hireDate = reader.GetDateTime(2);
       Console.WriteLine("Hire date: " + hireDate);
     }
     if (!reader.IsDBNull(3))
     {
       salary = reader.GetDouble(3);
       Console.WriteLine("Salary: " + salary);
     }
     if (!reader.IsDBNull(4))
     {
       jobDesc = reader.GetString(4);
       Console.WriteLine("Job Description: " + jobDesc);
     }
     if (!reader.IsDBNull(5))
     {
       long len = reader.GetBytes(5, 0, byteCodes, 0, 10);
       Console.Write("Byte codes: " );
       for (int i = 0; i < len; i++)
        Console.Write(byteCodes[i].ToString("x"));
       Console.WriteLine();
      }

      Console.WriteLine();
      //done reading one row
     } //Done Reading EMPINFO table

     //Close the reader
     reader.Close();

     // Close the connection
     connection.Close();
    }

Requirements

Namespace: Oracle.DataAccess.Client

Assembly: Oracle.DataAccesss.dll

See Also:

OracleDataReader Members

OracleDataReader members are listed in the following tables:

OracleDataReader Static Methods

OracleDataReader static methods are listed in Table 4-43.

Table 4-43 OracleDataReader Static Methods  
Methods Description

Equals

Inherited from Object (Overloaded)

OracleDataReader Properties

OracleDataReader properties are listed in Table 4-44.

Table 4-44 OracleDataReader Properties  
Property Description

Depth

Gets a value indicating the depth of nesting for the current row

FetchSize

Specifies the size of OracleDataReader's internal cache

FieldCount

Gets the number of columns in the result set

IsClosed

Indicates whether the data reader is closed

Item

Gets the value of the column (Overloaded)

InitialLONGFetchSize

Specifies the amount that the OracleDataReader initially fetches for LONG and LONG RAW columns

RecordsAffected

Gets the number of rows changed, inserted, or deleted by execution of the SQL statement

OracleDataReader Public Methods

OracleDataReader public methods are listed in Table 4-45.

Table 4-45 OracleDataReader Public Methods  
Public Method Description

Close

Closes the OracleDataReader

CreateObjRef

Inherited from MarshalByRefObject

Dispose

Releases any resources or memory allocated by the object

Equals

Inherited from Object (Overloaded)

GetBoolean

Not Supported

GetByte

Returns the byte value of the specified column

GetBytes

Populates the provided byte array with up to the maximum number of bytes, from the specified offset (in bytes) of the column

GetChar

Not Supported

GetChars

Populates the provided character array with up to the maximum number of characters, from the specified offset (in characters) of the column

GetData

Not Supported

GetDataTypeName

Returns the ODP.NET type name of the specified column

GetDateTime

Returns the DateTime value of the specified column

GetDecimal

Returns the decimal value of the specified NUMBER column

GetDouble

Returns the double value of the specified NUMBER column

GetFieldType

Returns the Type of the specified column

GetFloat

Returns the float value of the specified NUMBER column

GetGuid

Not Supported

GetHashCode

Inherited from Object

GetInt16

Returns the Int16 value of the specified NUMBER column

GetInt32

Returns the Int32 value of the specified NUMBER column

GetInt64

Returns the Int64 value of the specified NUMBER column

GetLifetimeService

Inherited by MarshalByRefObject

GetName

Returns the name of the specified column

GetOracleBFile

Returns an OracleBFile object of the specified BFILE column

GetOracleBinary

Returns an OracleBinary structure of the specified column

GetOracleBlob

Returns an OracleBlob object of the specified BLOB column

GetOracleBlobForUpdate

Returns an updatable OracleBlob object of the specified BLOB column

GetOracleClob

Returns an OracleClob object of the specified CLOB column

GetOracleClobForUpdate

Returns an updatable OracleClob object of the specified CLOB column

GetOracleDate

Returns an OracleDate structure of the specified DATE column

GetOracleDecimal

Returns an OracleDecimal structure of the specified NUMBER column

GetOracleIntervalDS

Returns an OracleIntervalDS structure of the specified INTERVAL DAY TO SECOND column

GetOracleIntervalYM

Returns an OracleIntervalYM structure of the specified INTERVAL YEAR TO MONTH column

GetOracleString

Returns an OracleString structure of the specified column

GetOracleTimeStamp

Returns an OracleTimeStamp structure of the Oracle TimeStamp column

GetOracleTimeStampLTZ

Returns an OracleTimeStampLTZ structure of the specified Oracle TimeStamp WITH LOCAL TIME ZONE column

GetOracleTimeStampTZ

Returns an OracleTimeStampTZ structure of the specified Oracle TimeStamp WITH TIME ZONE column

GetOracleValue

Returns the specified column value as a ODP.NET type

GetOracleValues

Gets all the column values as ODP.NET types

GetOrdinal

Returns the 0-based ordinal (or index) of the specified column name

GetSchemaTable

Returns a DataTable that describes the column metadata of the OracleDataReader

GetString

Returns the string value of the specified column

GetTimeSpan

Returns the TimeSpan value of the specified INTERVAL DAY TO SECOND column

GetType

Inherited from Object class

GetValue

Returns the column value as a .NET type

GetValues

Gets all the column values as .NET types

IsDBNull

Indicates whether the column value is null

NextResult

Advances the data reader to the next result set when reading the results

Read

Reads the next row in the result set

ToString

Inherited from Object

See Also:

OracleDataReader Static Methods

OracleDataReader static methods are listed in Table 4-46.

Table 4-46 OracleDataReader Static Methods  
Methods Description

Equals

Inherited from Object (Overloaded)

See Also:

OracleDataReader Properties

OracleDataReader properties are listed in Table 4-47.

Table 4-47 OracleDataReader Properties  
Property Description

Depth

Gets a value indicating the depth of nesting for the current row

FetchSize

Specifies the size of OracleDataReader's internal cache

FieldCount

Gets the number of columns in the result set

IsClosed

Indicates whether the data reader is closed

Item

Gets the value of the column (Overloaded)

InitialLONGFetchSize

Specifies the amount that the OracleDataReader initially fetches for LONG and LONG RAW columns

RecordsAffected

Gets the number of rows changed, inserted, or deleted by execution of the SQL statement

See Also:

Depth

This property gets a value indicating the depth of nesting for the current row.

Declaration
// C#
public int Depth {get;}
Property Value

The depth of nesting for the current row.

Implements

IDataReader

Exceptions

InvalidOperationException - The reader is closed.

Remarks

Default = 0

This property always returns zero because Oracle does not support nesting.

See Also:

FetchSize

This property specifies the size of OracleDataReader's internal cache.

Declaration
// C#
public long FetchSize {get;set;}  
Property Value

A long that specifies the amount of memory (in bytes) that the OracleDataReader uses for its internal cache.

Exceptions

ArgumentException - The FetchSize value specified is invalid.

Remarks

Default = The OracleCommand's FetchSize property value.

The FetchSize property is inherited by the OracleDataReader that is created by a command execution returning a result set. The FetchSize property on the OracleDataReader object determines the amount of data fetched into its internal cache per server round-trip.

See Also:

FieldCount

This property gets the number of columns in the result set.

Declaration
// C#
public int FieldCount {get;}
Property Value

The number of columns in the result set if one exists, otherwise 0.

Implements

IDataRecord

Exceptions

InvalidOperationException - The reader is closed.

Remarks

Default = 0

This property has a value of 0 for queries that do not return result sets.

See Also:

IsClosed

This property indicates whether the data reader is closed.

Declaration
// C#
public bool IsClosed {get;}
Property Value

If the OracleDataReader is in a closed state, returns true; otherwise, returns false.

Implements

IDataReader

Remarks

Default = true

IsClosed and RecordsAffected are the only two properties that are accessible after the OracleDataReader is closed.

See Also:

Item

This property gets the value of the column in .NET datatype.

Overload List:

Item [index]

This property gets the .NET Value of the column specified by the column index.

Declaration
// C#
public object this[int index] {get;}
Parameters
Property Value

The .NET value of the specified column.

Implements

IDataRecord

Remarks

Default = Not Applicable

In C#, this property is the indexer for this class.

See Also:

Item [string]

This property gets the .NET Value of the column specified by the column name.

Declaration
// C#
public object this[string columnName] {get;}
Parameters
Property Value

The .NET Value of the specified column.

Implements

IDataRecord

Remarks

Default = Not Applicable

A case-sensitive search is made to locate the specified column by its name. If this fails, then a case-insensitive search is made.

In C#, this property is the indexer for this class.

See Also:

InitialLONGFetchSize

This property specifies the amount that the OracleDataReader initially fetches for LONG and LONG RAW columns.

Declaration
// C#
public long InitialLONGFetchSize {get;}
Property Value

The size of the chunk to retrieve. The default is 0.

Exceptions

InvalidOperationException - The reader is closed.

Remarks

To fetch more than the InitialLONGFetchSize, the select list must contain a primary key or a ROWID.

The InitialLONGFetchSize value is used to determine the LONG or LONG RAW data to fetch if either is in the select-list. This value is ignored if the select-list does not contain either a LONG or a LONG RAW.

The amount is in number of characters for LONG data and in number of bytes for LONG RAW data. This value is inherited from OracleCommand.InitialLONGFetchSize.

See Also:

RecordsAffected

This property gets the number of rows changed, inserted, or deleted by execution of the SQL statement.

Declaration
// C#
public int RecordsAffected {get;}
Property Value

The number of rows affected by execution of the SQL statement.

Implements

IDataReader

Remarks

Default = 0

The value of -1 is returned for SELECT statements.

IsClosed and RecordsAffected are the only two properties that are accessible after the OracleDataReader is closed.

See Also:

OracleDataReader Public Methods

OracleDataReader public methods are listed in Table 4-48.

Table 4-48 OracleDataReader Public Methods  
Public Method Description

Close

Closes the OracleDataReader

CreateObjRef

Inherited from MarshalByRefObject

Dispose

Releases any resources or memory allocated by the object

Equals

Inherited from Object (Overloaded)

GetBoolean

Not Supported

GetByte

Returns the byte value of the specified column

GetBytes

Populates the provided byte array with up to the maximum number of bytes, from the specified offset (in bytes) of the column

GetChar

Not Supported

GetChars

Populates the provided character array with up to the maximum number of characters, from the specified offset (in characters) of the column

GetData

Not Supported

GetDataTypeName

Returns the ODP.NET type name of the specified column

GetDateTime

Returns the DateTime value of the specified column

GetDecimal

Returns the decimal value of the specified NUMBER column

GetDouble

Returns the double value of the specified NUMBER column

GetFieldType

Returns the Type of the specified column

GetFloat

Returns the float value of the specified NUMBER column

GetGuid

Not Supported

GetHashCode

Inherited from Object

GetInt16

Returns the Int16 value of the specified NUMBER column

GetInt32

Returns the Int32 value of the specified NUMBER column

GetInt64

Returns the Int64 value of the specified NUMBER column

GetLifetimeService

Inherited by MarshalByRefObject

GetName

Returns the name of the specified column

GetOracleBFile

Returns an OracleBFile object of the specified BFILE column

GetOracleBinary

Returns an OracleBinary structure of the specified column

GetOracleBlob

Returns an OracleBlob object of the specified BLOB column

GetOracleBlobForUpdate

Returns an updatable OracleBlob object of the specified BLOB column

GetOracleClob

Returns an OracleClob object of the specified CLOB column

GetOracleClobForUpdate

Returns an updatable OracleClob object of the specified CLOB column

GetOracleDate

Returns an OracleDate structure of the specified DATE column

GetOracleDecimal

Returns an OracleDecimal structure of the specified NUMBER column

GetOracleIntervalDS

Returns an OracleIntervalDS structure of the specified INTERVAL DAY TO SECOND column

GetOracleIntervalYM

Returns an OracleIntervalYM structure of the specified INTERVAL YEAR TO MONTH column

GetOracleString

Returns an OracleString structure of the specified column

GetOracleTimeStamp

Returns an OracleTimeStamp structure of the Oracle TimeStamp column

GetOracleTimeStampLTZ

Returns an OracleTimeStampLTZ structure of the specified Oracle TimeStamp WITH LOCAL TIME ZONE column

GetOracleTimeStampTZ

Returns an OracleTimeStampTZ structure of the specified Oracle TimeStamp WITH TIME ZONE column

GetOracleValue

Returns the specified column value as a ODP.NET type

GetOracleValues

Gets all the column values as ODP.NET types

GetOrdinal

Returns the 0-based ordinal (or index) of the specified column name

GetSchemaTable

Returns a DataTable that describes the column metadata of the OracleDataReader

GetString

Returns the string value of the specified column

GetTimeSpan

Returns the TimeSpan value of the specified INTERVAL DAY TO SECOND column

GetType

Inherited from Object class

GetValue

Returns the column value as a .NET type

GetValues

Gets all the column values as .NET types

IsDBNull

Indicates whether the column value is null

NextResult

Advances the data reader to the next result set when reading the results

Read

Reads the next row in the result set

ToString

Inherited from Object

See Also:

Close

This method closes the OracleDataReader.

Declaration
// C#
public void Close();
Implements

IDataReader

Remarks

The Close method frees all resources associated with the OracleDataReader.

Example

The code example for the OracleDataReader class includes the Close method. See OracleDataReader Overview "Example".

See Also:

Dispose

This method releases any resources or memory allocated by the object.

Declaration
// C#
public void Dispose();
Implements

IDisposable

Remarks

The Dispose method also closes the OracleDataReader.

See Also:

GetByte

This method returns the byte value of the specified column.

Declaration
// C#
public byte GetByte(int index);
Parameters
Return Value

The value of the column as a byte.

Implements

IDataRecord

Exceptions

InvalidOperationException - The connection is closed, the reader is closed, Read() has not been called, or all rows have been read.

IndexOutOfRangeException - The column index is invalid.

InvalidCastException - The accessor method is invalid for this column type or the column value is NULL.

Remarks

IsDBNull should be called to check for NULL values before calling this method.

See Also:

GetBytes

This method populates the provided byte array with up to the maximum number of bytes, from the specified offset (in bytes) of the column.

Declaration
// C#
public long GetBytes(int index, long fieldOffset, byte[] buffer, int 
bufferOffset, int length);
Parameters
Return Value

The number of bytes read.

Implements

IDataRecord

Exceptions

InvalidOperationException - The connection is closed, the reader is closed, Read() has not been called, or all rows have been read.

IndexOutOfRangeException - The column index is invalid.

InvalidCastException - The accessor method is invalid for this column type or the column value is NULL.

Remarks

This method returns the number of bytes read into the buffer. This may be less than the actual length of the field if the method has been called previously for the same column.

If a null reference is passed for buffer, the length of the field in bytes is returned.

IsDBNull should be called to check for NULL values before calling this method.

See Also:

GetChars

This method populates the provided character array with up to the maximum number of characters, from the specified offset (in characters) of the column.

Declaration
// C#
public long GetChars(int index, long fieldOffset, char[] buffer, int 
bufferOffset, int length);
Parameters
Return Value

The number of characters read.

Implements

IDataRecord

Exceptions

InvalidOperationException - The connection is closed, the reader is closed, Read() has not been called, or all rows have been read.

IndexOutOfRangeException - The column index is invalid.

InvalidCastException - The accessor method is invalid for this column type or the column value is NULL.

Remarks

This method returns the number of characters read into the buffer. This may be less than the actual length of the field, if the method has been called previously for the same column.

If a null reference is passed for buffer, the length of the field in characters is returned.

IsDBNull should be called to check for NULL values before calling this method.

See Also:

GetDataTypeName

This method returns the ODP.NET type name of the specified column.

Declaration
// C#
public string GetDataTypeName(int index);
Parameters
Return Value

The name of the ODP.NET type of the column.

Implements

IDataRecord

Exceptions

InvalidOperationException - The reader is closed.

IndexOutOfRangeException - The column index is invalid.

See Also:

GetDateTime

This method returns the DateTime value of the specified column.

Declaration
// C#
public DateTime GetDateTime(int index);
Parameters
Return Value

The DateTime value of the column.

Implements

IDataRecord

Exceptions

InvalidOperationException - The connection is closed, the reader is closed, Read() has not been called, or all rows have been read.

IndexOutOfRangeException - The column index is invalid.

InvalidCastException - The accessor method is invalid for this column type or the column value is NULL.

Remarks

IsDBNull should be called to check for NULL values before calling this method.

See Also:

GetDecimal

This method returns the decimal value of the specified NUMBER column.

Declaration
// C#
public decimal GetDecimal(int index);
Parameters
Return Value

The decimal value of the column.

Implements

IDataRecord

Exceptions

InvalidOperationException - The connection is closed, the reader is closed, Read() has not been called, or all rows have been read.

IndexOutOfRangeException - The column index is invalid.

InvalidCastException - The accessor method is invalid for this column type or the column value is NULL.

Remarks

IsDBNull should be called to check for NULL values before calling this method.

See Also:

GetDouble

This method returns the double value of the specified NUMBER column.

Declaration
// C#
public double GetDouble(int index);
Parameters
Return Value

The double value of the column.

Implements

IDataRecord

Exceptions

InvalidOperationException - The connection is closed, the reader is closed, Read() has not been called, or all rows have been read.

IndexOutOfRangeException - The column index is invalid.

InvalidCastException - The accessor method is invalid for this column type or the column value is NULL.

Remarks

IsDBNull should be called to check for NULL values before calling this method.

See Also:

GetFieldType

This method returns the Type of the specified column.

Declaration
// C#
public Type GetFieldType(int index);
Parameters
Return Value

The Type of the default .NET type of the column.

Implements

IDataRecord

Exceptions

InvalidOperationException - The reader is closed.

IndexOutOfRangeException - The column index is invalid.

See Also:

GetFloat

This method returns the float value of the specified NUMBER column.

Declaration
// C#
public float GetFloat(int index);
Parameters
Return Value

The float value of the column.

Implements

IDataRecord

Exceptions

InvalidOperationException - The connection is closed, the reader is closed, Read() has not been called, or all rows have been read.

IndexOutOfRangeException - The column index is invalid.

InvalidCastException - The accessor method is invalid for this column type or the column value is NULL.

Remarks

IsDBNull should be called to check for NULL values before calling this method.

See Also:

GetInt16

This method returns the Int16 value of the specified NUMBER column.


Note:

short is equivalent to Int16.


Declaration
// C#
public short GetInt16(int index);
Parameters
Return Value

The Int16 value of the column.

Implements

IDataRecord

Exceptions

InvalidOperationException - The connection is closed, the reader is closed, Read() has not been called, or all rows have been read.

IndexOutOfRangeException - The column index is invalid.

InvalidCastException - The accessor method is invalid for this column type or the column value is NULL.

Remarks

IsDBNull should be called to check for NULL values before calling this method.

See Also:

GetInt32

This method returns the Int32 value of the specified NUMBER column.


Note:

int is equivalent to Int32.


Declaration
// C#
public int GetInt32(int index);
Parameters
Return Value

The Int32 value of the column.

Implements

IDataRecord

Exceptions

InvalidOperationException - The connection is closed, the reader is closed, Read() has not been called, or all rows have been read.

IndexOutOfRangeException - The column index is invalid.

InvalidCastException - The accessor method is invalid for this column type or the column value is NULL.

Remarks

IsDBNull should be called to check for NULL values before calling this method.

See Also:

GetInt64

This method returns the Int64 value of the specified NUMBER column.


Note:

long is equivalent to Int64.


Declaration
// C#
public long GetInt64(int index);
Parameters
Return Value

The Int64 value of the column.

Implements

IDataRecord

Exceptions

InvalidOperationException - The connection is closed, the reader is closed, Read() has not been called, or all rows have been read.

IndexOutOfRangeException - The column index is invalid.

InvalidCastException - The accessor method is invalid for this column type or the column value is NULL.

Remarks

IsDBNull should be called to check for NULL values before calling this method.

See Also:

GetName

This method returns the name of the specified column.

Declaration
// C#
public string GetName(int index);
Parameters
Return Value

The name of the column.

Implements

IDataRecord

Exceptions

InvalidOperationException - The reader is closed.

IndexOutOfRangeException - The column index is invalid.

See Also:

GetOracleBFile

This method returns an OracleBFile object of the specified BFILE column.

Declaration
// C#
public OracleBFile GetOracleBFile(int index);
Parameters
Return Value

The OracleBFile value of the column.

Exceptions

InvalidOperationException - The connection is closed, the reader is closed, Read() has not been called, or all rows have been read.

IndexOutOfRangeException - The column index is invalid.

InvalidCastException - The accessor method is invalid for this column type or the column value is NULL.

Remarks

IsDBNull should be called to check for NULL values before calling this method.

See Also:

GetOracleBinary

This method returns an OracleBinary structure of the specified column.

Declaration
// C#
public OracleBinary GetOracleBinary(int index);
Parameters
Return Value

The OracleBinary value of the column.

Exceptions

InvalidOperationException - The connection is closed, the reader is closed, Read() has not been called, or all rows have been read.

IndexOutOfRangeException - The column index is invalid.

InvalidCastException - The accessor method is invalid for this column type or the column value is NULL.

Remarks

IsDBNull should be called to check for NULL values before calling this method.

GetOracleBinary is used on the following Oracle types:

GetOracleBlob

This method returns an OracleBlob object of the specified BLOB column.

Declaration
// C#
public OracleBlob GetOracleBlob(int index);
Parameters
Return Value

The OracleBlob value of the column.

Exceptions

InvalidOperationException - The connection is closed, the reader is closed, Read() has not been called, or all rows have been read.

IndexOutOfRangeException - The column index is invalid.

InvalidCastException - The accessor method is invalid for this column type or the column value is NULL.

Remarks

IsDBNull should be called to check for NULL values before calling this method.

See Also:

GetOracleBlobForUpdate

GetOracleBlobForUpdate returns an updatable OracleBlob object of the specified BLOB column.

Overload List:

GetOracleBlobForUpdate(int)

This method returns an updatable OracleBlob object of the specified BLOB column.

Declaration
// C#
public OracleBlob GetOracleBlobForUpdate(int index);
Parameters
Return Value

An updatable OracleBlob object.

Exceptions

InvalidOperationException - The connection is closed, the reader is closed, Read() has not been called, or all rows have been read.

IndexOutOfRangeException - The column index is invalid.

InvalidCastException - The accessor method is invalid for this column type or the column value is NULL.

Remarks

When the OracleCommand's ExecuteReader() method is invoked, all the data fetched by the OracleDataReader is from a particular snapshot. Therefore, calling an accessor method on the same column always returns the same value. However, the GetOracleBlobForUpdate() method incurs a server round-trip to obtain a reference to the current BLOB data while also locking the row using the FOR UPDATE clause. This means that the OracleBlob obtained from GetOracleBlob() can have a different value than the OracleBlob obtained from GetOracleBlobForUpdate() since it is not obtained from the original snapshot.

The returned OracleBlob object can be used to safely update the BLOB because the BLOB column has been locked after a call to this method.

Invoking this method internally executes a SELECT..FOR UPDATE statement without a WAIT clause. Therefore, the statement can wait indefinitely until a lock is acquired for that row.

IsDBNull should be called to check for NULL values before calling this method.

Example

The following example gets the OracleBlob object for update from the reader, updates the OracleBlob object, and then commits the transaction.

// C#
public static void ReadOracleBlobForUpdate(string connStr)
  {
   //get the job description for empno = 1
   string cmdStr = "SELECT BYTECODES, EMPNO FROM EMPINFO where EMPNO = 1";

   OracleConnection connection = new OracleConnection(connStr);
   OracleCommand cmd = new OracleCommand(cmdStr, connection);
   connection.Open();

   //Since we are going to update the OracleBlob object, we will
   //have to create a transaction
   OracleTransaction txn = connection.BeginTransaction();

   //get the reader
   OracleDataReader reader = cmd.ExecuteReader();

   //declare the variables to retrieve the data in EmpInfo
   OracleBlob byteCodesBlob;

   //read the first row
   reader.Read();

   if (!reader.IsDBNull(0))
   {
     byteCodesBlob = reader.GetOracleBlobForUpdate(0);

     //Close the reader
     reader.Close();

     //Update the job description Clob object
     byte[] addedBytes = new byte[2] {0, 0};
     byteCodesBlob.Append(addedBytes, 0, addedBytes.Length);

     //Now commit the transaction
     txn.Commit();
    }
    else
      reader.Close();

    // Close the connection
    connection.Close();
  }

See Also:

GetOracleBlobForUpdate(int, int)

This method returns an updatable OracleBlob object of the specified BLOB column using a WAIT clause.

Declaration
// C#
public OracleBlob GetOracleBlobForUpdate(int index, int wait);
Parameters
Return Value

An updatable OracleBlob object.

Exceptions

InvalidOperationException - The connection is closed, the reader is closed, Read() has not been called, or all rows have been read.

IndexOutOfRangeException - The column index is invalid.

InvalidCastException - The accessor method is invalid for this column type or the column value is NULL.

Remarks

When the OracleCommand's ExecuteReader() method is invoked, all the data fetched by the OracleDataReader is from a particular snapshot. Therefore, calling an accessor method on the same column always returns the same value. However, the GetOracleBlobForUpdate() method incurs a server round-trip to obtain a reference to the current BLOB data while also locking the row using the FOR UPDATE clause. This means that the OracleBlob obtained from GetOracleBlob() can have a different value than the OracleBlob obtained from GetOracleBlobForUpdate() since it is not obtained from the original snapshot.

IsDBNull should be called to check for NULL values before calling this method.

The returned OracleBlob object can be used to safely update the BLOB because the BLOB column has been locked after a call to this method.

Invoking this method internally executes a SELECT..FOR UPDATE statement which locks the row.

Different WAIT clauses are appended to the statement, depending on the wait value. If the wait value is:

Example

The GetOracleBlobForUpdate methods are comparable. See "Example" for a code example demonstrating usage.

See Also:

GetOracleClob

This method returns an OracleClob object of the specified CLOB column.

Declaration
// C#
public OracleClob GetOracleClob(int index);
Parameters
Return Value

The OracleClob value of the column.

Exceptions

InvalidOperationException - The connection is closed, the reader is closed, Read() has not been called, or all rows have been read.

IndexOutOfRangeException - The column index is invalid.

InvalidCastException - The accessor method is invalid for this column type or the column value is NULL.

Remarks

IsDBNull should be called to check for NULL values before calling this method.

See Also:

GetOracleClobForUpdate

GetOracleClobForUpdate returns an updatable OracleClob object of the specified CLOB column.

Overload List:

GetOracleClobForUpdate(int)

This method returns an updatable OracleClob object of the specified CLOB column.

Declaration
// C#
public OracleClob GetOracleClobForUpdate(int index);
Parameters
Return Value

An updatable OracleClob.

Exceptions

InvalidOperationException - The connection is closed, the reader is closed, Read() has not been called, or all rows have been read.

IndexOutOfRangeException - The column index is invalid.

InvalidCastException - The accessor method is invalid for this column type or the column value is NULL.

Remarks

When the OracleCommand's ExecuteReader() method is invoked, all the data fetched by the OracleDataReader is from a particular snapshot. Therefore, calling an accessor method on the same column always returns the same value. However, the GetOracleClobForUpdate() method incurs a server round-trip to obtain a reference to the current CLOB data while also locking the row using the FOR UPDATE clause. This means that the OracleClob obtained from GetOracleClob() can have a different value than the OracleClob obtained from GetOracleClobForUpdate() since it is not obtained from the original snapshot.

The returned OracleClob object can be used to safely update the CLOB because the CLOB column is locked after a call to this method.

Invoking this method internally executes a SELECT..FOR UPDATE statement without a WAIT clause. Therefore, the statement can wait indefinitely until a lock is acquired for that row.

IsDBNull should be called to check for NULL values before calling this method.

Example

The following example gets the OracleClob object for update from the reader, updates the OracleClob object, and then commits the transaction.

// C#
public static void ReadOracleClobForUpdate(string connStr)
  {
    //get the job description for empno = 1
    string cmdStr = "SELECT JOBDESCRIPTION, EMPNO FROM EMPINFO where EMPNO = 1";

    OracleConnection connection = new OracleConnection(connStr);
    OracleCommand cmd = new OracleCommand(cmdStr, connection);
    connection.Open();

    //Since we are going to update the OracleClob object, we will
    //have to create a transaction
    OracleTransaction txn = connection.BeginTransaction();

    //get the reader
    OracleDataReader reader = cmd.ExecuteReader();

    //declare the variables to retrieve the data in EmpInfo
    OracleClob jobDescClob;

    //read the first row
    reader.Read();

    if (!reader.IsDBNull(0))
    {
      jobDescClob = reader.GetOracleClobForUpdate(0);

      //Close the reader
      reader.Close();

      //Update the job description Clob object
      char[] jobDesc = "-SALES".ToCharArray();
      jobDescClob.Append(jobDesc, 0, jobDesc.Length);

      //Now commit the transaction
      txn.Commit();
    }
    else
      reader.Close();

    // Close the connection
    connection.Close();
  }

See Also:

GetOracleClobForUpdate(int, int)

This method returns an updatable OracleClob object of the specified CLOB column using a WAIT clause.

Declaration
// C#
public OracleClob GetOracleClobForUpdate(int index, int wait);
Parameters
Return Value

An updatable OracleClob.

Exceptions

InvalidOperationException - The connection is closed, the reader is closed, Read() has not been called, or all rows have been read.

IndexOutOfRangeException - The column index is invalid.

InvalidCastException - The accessor method is invalid for this column type or the column value is NULL.

Remarks

When the OracleCommand's ExecuteReader() method is invoked, all the data fetched by the OracleDataReader is from a particular snapshot. Therefore, calling an accessor method on the same column always returns the same value. However, the GetOracleClobForUpdate() method incurs a server round-trip to obtain a reference to the current CLOB data while also locking the row using the FOR UPDATE clause. This means that the OracleClob obtained from GetOracleClob() can have a different value than the OracleClob obtained from GetOracleClobForUpdate() since it is not obtained from the original snapshot.

Invoking this method internally executes a SELECT..FOR UPDATE statement which locks the row.

The returned OracleClob object can be used to safely update the CLOB because the CLOB column is locked after a call to this method.

Different WAIT clauses are appended to the statement, depending on the wait value. If the wait value is:

IsDBNull should be called to check for NULL values before calling this method.

Example

The GetOracleClobForUpdate methods are comparable. See "Example" for a code example demonstrating usage.

See Also:

GetOracleDate

This method returns an OracleDate structure of the specified DATE column.

Declaration
// C#
public OracleDate GetOracleDate(int index);
Parameters
Return Value

The OracleDate value of the column.

Exceptions

InvalidOperationException - The connection is closed, the reader is closed, Read() has not been called, or all rows have been read.

IndexOutOfRangeException - The column index is invalid.

InvalidCastException - The accessor method is invalid for this column type or the column value is NULL.

Remarks

IsDBNull should be called to check for NULL values before calling this method.

See Also:

GetOracleDecimal

This method returns an OracleDecimal structure of the specified NUMBER column.

Declaration
// C#
public OracleDecimal GetOracleDecimal(int index);
Parameters
Return Value

The OracleDecimal value of the column.

Exceptions

InvalidOperationException - The connection is closed, the reader is closed, Read() has not been called, or all rows have been read.

IndexOutOfRangeException - The column index is invalid.

InvalidCastException - The accessor method is invalid for this column type or the column value is NULL.

Remarks

IsDBNull should be called to check for NULL values before calling this method.

See Also:

GetOracleIntervalDS

This method returns an OracleIntervalDS structure of the specified INTERVAL DAY TO SECOND column.

Declaration
// C#
public OracleIntervalDS GetOracleIntervalDS(int index);
Parameters
Return Value

The OracleIntervalDS value of the column.

Exceptions

InvalidOperationException - The connection is closed, the reader is closed, Read() has not been called, or all rows have been read.

IndexOutOfRangeException - The column index is invalid.

InvalidCastException - The accessor method is invalid for this column type or the column value is NULL.

Remarks

IsDBNull should be called to check for NULL values before calling this method.

See Also:

GetOracleIntervalYM

This method returns an OracleIntervalYM structure of the specified INTERVAL YEAR TO MONTH column.

Declaration
// C#
public OracleIntervalYM GetOracleIntervalYM(int index);
Parameters
Return Value

The OracleIntervalYM value of the column.

Exceptions

InvalidOperationException - The connection is closed, the reader is closed, Read() has not been called, or all rows have been read.

IndexOutOfRangeException - The column index is invalid.

InvalidCastException - The accessor method is invalid for this column type or the column value is NULL.

Remarks

IsDBNull should be called to check for NULL values before calling this method.

See Also:

GetOracleString

This method returns an OracleString structure of the specified column. The string is stored as a Unicode string.

Declaration
// C#
public OracleString GetOracleString(int index);
Parameters
Return Value

The OracleString value of the column.

Exceptions

InvalidOperationException - The connection is closed, the reader is closed, Read() has not been called, or all rows have been read.

IndexOutOfRangeException - The column index is invalid.

InvalidCastException - The accessor method is invalid for this column type or the column value is NULL.

Remarks

IsDBNull should be called to check for NULL values before calling this method.

GetOracleString is used on the following Oracle column types:

GetOracleTimeStamp

This method returns an OracleTimeStamp structure of the Oracle TimeStamp column.

Declaration
// C#
public OracleTimeStamp GetOracleTimeStamp(int index);
Parameters
Return Value

The OracleTimeStamp value of the column.

Exceptions

InvalidOperationException - The connection is closed, the reader is closed, Read() has not been called, or all rows have been read.

IndexOutOfRangeException - The column index is invalid.

InvalidCastException - The accessor method is invalid for this column type or the column value is NULL.

Remarks

GetOracleTimeStamp is used with the Oracle Type TimeStamp.

IsDBNull should be called to check for NULL values before calling this method.

See Also:

GetOracleTimeStampLTZ

This method returns an OracleTimeStampLTZ structure of the specified Oracle TimeStamp WITH LOCAL TIME ZONE column.

Declaration
// C#
public OracleTimeStampLTZ GetOracleTimeStampLTZ(int index);
Parameters
Return Value

The OracleTimeStampLTZ value of the column.

Exceptions

InvalidOperationException - The connection is closed, the reader is closed, Read() has not been called, or all rows have been read.

IndexOutOfRangeException - The column index is invalid.

InvalidCastException - The accessor method is invalid for this column type or the column value is NULL.

Remarks

GetOracleTimeStampLTZ is used with the Oracle Type TimeStamp with Local Time Zone columns.

IsDBNull should be called to check for NULL values before calling this method.

See Also:

GetOracleTimeStampTZ

This method returns an OracleTimeStampTZ structure of the specified Oracle TimeStamp WITH TIME ZONE column.

Declaration
// C#
public OracleTimeStampTZ GetOracleTimeStampTZ(int index);
Parameters
Return Value

The OracleTimeStampTZ value of the column.

Exceptions

InvalidOperationException - The connection is closed, the reader is closed, Read() has not been called, or all rows have been read.

IndexOutOfRangeException - The column index is invalid.

InvalidCastException - The accessor method is invalid for this column type or the column value is NULL.

Remarks

Used with the Oracle Type TimeStamp with Local Time Zone columns

IsDBNull should be called to check for NULL values before calling this method.

See Also:

GetOracleValue

This method returns the specified column value as a ODP.NET type.

Declaration
// C#
public object GetOracleValue(int index);
Parameters
Return Value

The value of the column as an ODP.NET type.

Exceptions

InvalidOperationException - The connection is closed, the reader is closed, Read() has not been called, or all rows have been read.

IndexOutOfRangeException - The column index is invalid.

See Also:

GetOracleValues

This method gets all the column values as ODP.NET types.

Declaration
// C#
public int GetOracleValues(object[] values);
Parameters
Return Value

The number of ODP.NET types in the values array.

Exceptions

InvalidOperationException - The connection is closed, the reader is closed, Read() has not been called, or all rows have been read.

Remarks

This method provides a way to retrieve all column values rather than retrieving each column value individually.

The number of column values retrieved is the minimum of the length of the values array and the number of columns in the result set.

See Also:

GetOrdinal

This method returns the 0-based ordinal (or index) of the specified column name.

Declaration
// C#
public int GetOrdinal(string name);
Parameters
Return Value

The index of the column.

Implements

IDataRecord

Exceptions

InvalidOperationException - The reader is closed.

IndexOutOfRangeException - The column index is invalid.

Remarks

A case-sensitive search is made to locate the specified column by its name. If this fails, then a case-insensitive search is made.

See Also:

GetSchemaTable

This method returns a DataTable that describes the column metadata of the OracleDataReader.

Declaration
// C#
public DataTable GetSchemaTable();
Return Value

A DataTable that contains the metadata of the result set.

Implements

IDataReader

Exceptions

InvalidOperationException - The connection is closed or the reader is closed.

Remarks

OracleDataReader.GetSchemaTable()returns the SchemaTable.

OracleDataReader SchemaTable

The OracleDataReader SchemaTable is a DataTable that describes the column metadata of the OracleDataReader.

The columns of the SchemaTable are in the order shown.

Table 4-49 OracleDataReader SchemaTable  
Name Name Type Description

ColumnName

System.String

The name of the column.

ColumnOrdinal

System.Int32

The 0-based ordinal of the column.

ColumnSize

System.Int64

The maximum possible length of a value in the column. ColumnSize value is determined as follows:

  • CHAR and VARCHAR2 types:

    in bytes - if IsByteSemantic boolean value is true

    in characters - if IsByteSemantic boolean value is false

  • All other types:

    in bytes

See "IsByteSemantic" for more information.

NumericPrecision

System.Int16

The maximum precision of the column, if the column is a numeric datatype.

This column has valid values for Oracle NUMBER, Oracle INTERVAL YEAR TO MONTH, and Oracle INTERVAL DAY TO SECOND columns. For all other columns, the value is null.

NumericScale

System.Int16

The scale of the column.

This column has valid values for Oracle NUMBER, Oracle INTERVAL DAY TO SECOND, and the Oracle TIMESTAMP columns. For all other columns, the value is null.

IsUnique

System.Boolean

Indicates whether the column is unique.

IsKey

System.Boolean

Indicates whether the column is a key column.

IsRowID

System.Boolean

true if the column is a ROWID, otherwise false.

BaseColumnName

System.String

The name of the column in the database if an alias is used for the column.

BaseSchemaName

System.String

The name of the schema in the database that contains the column.

BaseTableName

System.String

The name of the table or view in the database that contains the column.

DataType

System.RuntimeType

Maps to the common language runtime type.

ProviderType

Oracle.DataAccess. Client.OracleDbType

The database column type (OracleDbType) of the column.

AllowDBNull

System.Boolean

true if null values are allowed, otherwise false.

IsAliased

System.Boolean

true if the column is an alias; otherwise false.

IsByteSemantic

System.Boolean

IsByteSemantic is:

  • true if the ColumnSize value uses bytes semantics

  • false if ColumnSize uses character semantics

This value is always true when connected to a database version earlier than Oracle9i Server.

IsExpression

System.Boolean

true if the column is an expression; otherwise false.

IsHidden

System.Boolean

true if the column is hidden; otherwise false.

IsReadOnly

System.Boolean

true if the column is read-only; otherwise false.

IsLong

System.Boolean

true if the column is a LONG, LONG RAW, BLOB, CLOB, or BFILE; otherwise false.

Example

This example creates and uses the SchemaTable from the reader.

// C#
public static void ReadSchemaTable(string connStr)
 {
   .....

 //get the reader
 OracleDataReader reader = cmd.ExecuteReader();

 //get the schema table
 DataTable schemaTable = reader.GetSchemaTable();

 //retrieve the first column info.
 DataRow col0 = schemaTable.Rows[0];

 //print out the column info
 Console.WriteLine("Column name: " + col0["COLUMNNAME"]);
 Console.WriteLine("Precision: " + col0["NUMERICPRECISION"]);
 Console.WriteLine("Scale: " + col0["NUMERICSCALE"]);
 .....

 }

See Also:

GetString

This method returns the string value of the specified column.

Declaration
// C#
public string GetString(int index);
Parameters
Return Value

The string value of the column.

Implements

IDataRecord

Exceptions

InvalidOperationException - The connection is closed, the reader is closed, Read() has not been called, or all rows have been read.

IndexOutOfRangeException - The column index is invalid.

InvalidCastException - The accessor method is invalid for this column type or the column value is NULL.

Remarks

IsDBNull should be called to check for NULL values before calling this method.

See Also:

GetTimeSpan

This method returns the TimeSpan value of the specified INTERVAL DAY TO SECOND column.

Declaration
// C#
public TimeSpan GetTimeSpan(int index);
Parameters
Return Value

The TimeSpan value of the column.

Implements

IDataRecord

Exceptions

InvalidOperationException - The connection is closed, the reader is closed, Read() has not been called, or all rows have been read.

IndexOutOfRangeException - The column index is invalid.

InvalidCastException - The accessor method is invalid for this column type or the column value is NULL.

Remarks

IsDBNull should be called to check for NULL values before calling this method.

See Also:

GetValue

This method returns the column value as a .NET type.

Declaration
// C#
public object GetValue(int index);
Parameters
Return Value

The value of the column as a .NET type.

Implements

IDataRecord

Exceptions

InvalidOperationException - The connection is closed, the reader is closed, Read() has not been called, or all rows have been read.

IndexOutOfRangeException - The column index is invalid.

See Also:

GetValues

This method gets all the column values as .NET types.

Declaration
// C#
public int GetValues(object[ ] values);
Parameters
Return Value

The number of objects in the values array.

Implements

IDataRecord

Exceptions

InvalidOperationException - The connection is closed, the reader is closed, Read() has not been called, or all rows have been read.

Remarks

This method provides a way to retrieve all column values rather than retrieving each column value individually.

The number of column values retrieved is the minimum of the length of the values array and the number of columns in the result set.

See Also:

IsDBNull

This method indicates whether the column value is NULL.

Declaration
// C#
public bool IsDBNull(int index);
Parameters
Return Value

Returns true if the column is a NULL value; otherwise, returns false.

Implements

IDataRecord

Exceptions

InvalidOperationException - The reader is closed, Read() has not been called, or all rows have been read.

IndexOutOfRangeException - The column index is invalid.

Remarks

This method should be called to check for NULL values before calling the other accessor methods.

Example

The code example for the OracleDataReader class includes the IsDBNull method. See "Example".

See Also:

NextResult

This method advances the data reader to the next result set.

Declaration
// C#
public bool NextResult();
Return Value

Returns true if another result set exists; otherwise, returns false.

Implements

IDataReader

Exceptions

InvalidOperationException - The connection is closed or the reader is closed.

Remarks

NextResult is used when reading results from stored procedure execution that return more than one result set.

See Also:

Read

This method reads the next row in the result set.

Declaration
// C#
public bool Read();
Return Value

Returns true if another row exists; otherwise, returns false.

Implements

IDataReader

Exceptions

InvalidOperationException - The connection is closed or the reader is closed.

Remarks

The initial position of the data reader is before the first row. Therefore, the Read method must be called to fetch the first row. The row that was just read is considered the current row. If the OracleDataReader has no more rows to read, it returns false.

Example

The code example for the OracleDataReader class includes the Read method. See "Example".

See Also:


Go to previous page Go to beginning of chapter Go to next page
Oracle
Copyright © 2002 Oracle Corporation.

All Rights Reserved.
Go To Table Of Contents
Contents
Go To Index
Index