| Oracle Data Provider for .NET Developer's Guide Release 9.2.0.2 Part Number A96160-01 |
|
Oracle.DataAccess.Client Namespace, 6 of 26
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.
Object
MarshalByRefObject
OracleDataReader
// C# public sealed class OracleDataReader : MarshalByRefObject, IEnumerable, IDataReader, IDisposable, IDataRecord
All public static methods are thread-safe, although instance methods do not guarantee thread safety.
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.
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(); }
Namespace: Oracle.DataAccess.Client
Assembly: Oracle.DataAccesss.dll
OracleDataReader members are listed in the following tables:
OracleDataReader static methods are listed in Table 4-43.
| Methods | Description |
|---|---|
|
|
Inherited from |
OracleDataReader properties are listed in Table 4-44.
OracleDataReader public methods are listed in Table 4-45.
OracleDataReader static methods are listed in Table 4-46.
| Methods | Description |
|---|---|
|
|
Inherited from |
OracleDataReader properties are listed in Table 4-47.
This property gets a value indicating the depth of nesting for the current row.
// C# public int Depth {get;}
The depth of nesting for the current row.
IDataReader
InvalidOperationException - The reader is closed.
Default = 0
This property always returns zero because Oracle does not support nesting.
This property specifies the size of OracleDataReader's internal cache.
// C# public long FetchSize {get;set;}
A long that specifies the amount of memory (in bytes) that the OracleDataReader uses for its internal cache.
ArgumentException - The FetchSize value specified is invalid.
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:
|
This property gets the number of columns in the result set.
// C# public int FieldCount {get;}
The number of columns in the result set if one exists, otherwise 0.
IDataRecord
InvalidOperationException - The reader is closed.
Default = 0
This property has a value of 0 for queries that do not return result sets.
This property indicates whether the data reader is closed.
// C# public bool IsClosed {get;}
If the OracleDataReader is in a closed state, returns true; otherwise, returns false.
IDataReader
Default = true
IsClosed and RecordsAffected are the only two properties that are accessible after the OracleDataReader is closed.
This property gets the value of the column in .NET datatype.
This property gets the .NET Value of the column specified by the column index.
This property gets the .NET Value of the column specified by the column name.
This property gets the .NET Value of the column specified by the column index.
// C# public object this[int index] {get;}
The .NET value of the specified column.
IDataRecord
Default = Not Applicable
In C#, this property is the indexer for this class.
This property gets the .NET Value of the column specified by the column name.
// C# public object this[string columnName] {get;}
The .NET Value of the specified column.
IDataRecord
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.
This property specifies the amount that the OracleDataReader initially fetches for LONG and LONG RAW columns.
// C# public long InitialLONGFetchSize {get;}
The size of the chunk to retrieve. The default is 0.
InvalidOperationException - The reader is closed.
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.
This property gets the number of rows changed, inserted, or deleted by execution of the SQL statement.
// C# public int RecordsAffected {get;}
The number of rows affected by execution of the SQL statement.
IDataReader
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.
OracleDataReader public methods are listed in Table 4-48.
This method closes the OracleDataReader.
// C# public void Close();
IDataReader
The Close method frees all resources associated with the OracleDataReader.
The code example for the OracleDataReader class includes the Close method. See OracleDataReader Overview "Example".
This method releases any resources or memory allocated by the object.
// C# public void Dispose();
IDisposable
The Dispose method also closes the OracleDataReader.
This method returns the byte value of the specified column.
// C# public byte GetByte(int index);
The value of the column as a byte.
IDataRecord
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.
IsDBNull should be called to check for NULL values before calling this method.
This method populates the provided byte array with up to the maximum number of bytes, from the specified offset (in bytes) of the column.
// C#public long GetBytes(intindex, longfieldOffset, byte[]buffer, intbufferOffset, intlength);
index
The zero-based column index.
fieldOffset
The offset within the column from which reading begins (in bytes).
buffer
The byte array that the data is read into.
bufferOffset
The offset within the buffer to begin reading data into (in bytes).
length
The maximum number of bytes to read (in bytes).
The number of bytes read.
IDataRecord
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.
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.
This method populates the provided character array with up to the maximum number of characters, from the specified offset (in characters) of the column.
// C# public long GetChars(int index, long fieldOffset, char[] buffer, int bufferOffset, int length);
index
The zero based column index.
fieldOffset
The index within the column from which to begin reading (in characters).
buffer
The character array that the data is read into.
bufferOffset
The index within the buffer to begin reading data into (in characters).
length
The maximum number of characters to read (in characters).
The number of characters read.
IDataRecord
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.
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.
This method returns the ODP.NET type name of the specified column.
// C# public string GetDataTypeName(int index);
The name of the ODP.NET type of the column.
IDataRecord
InvalidOperationException - The reader is closed.
IndexOutOfRangeException - The column index is invalid.
This method returns the DateTime value of the specified column.
// C# public DateTime GetDateTime(int index);
The DateTime value of the column.
IDataRecord
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.
IsDBNull should be called to check for NULL values before calling this method.
This method returns the decimal value of the specified NUMBER column.
// C# public decimal GetDecimal(int index);
The decimal value of the column.
IDataRecord
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.
IsDBNull should be called to check for NULL values before calling this method.
This method returns the double value of the specified NUMBER column.
// C# public double GetDouble(int index);
The double value of the column.
IDataRecord
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.
IsDBNull should be called to check for NULL values before calling this method.
This method returns the Type of the specified column.
// C# public Type GetFieldType(int index);
The Type of the default .NET type of the column.
IDataRecord
InvalidOperationException - The reader is closed.
IndexOutOfRangeException - The column index is invalid.
This method returns the float value of the specified NUMBER column.
// C# public float GetFloat(int index);
The float value of the column.
IDataRecord
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.
IsDBNull should be called to check for NULL values before calling this method.
This method returns the Int16 value of the specified NUMBER column.
// C#public short GetInt16(intindex);
The Int16 value of the column.
IDataRecord
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.
IsDBNull should be called to check for NULL values before calling this method.
This method returns the Int32 value of the specified NUMBER column.
// C# public int GetInt32(int index);
The Int32 value of the column.
IDataRecord
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.
IsDBNull should be called to check for NULL values before calling this method.
This method returns the Int64 value of the specified NUMBER column.
// C# public long GetInt64(int index);
The Int64 value of the column.
IDataRecord
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.
IsDBNull should be called to check for NULL values before calling this method.
This method returns the name of the specified column.
// C# public string GetName(int index);
The name of the column.
IDataRecord
InvalidOperationException - The reader is closed.
IndexOutOfRangeException - The column index is invalid.
This method returns an OracleBFile object of the specified BFILE column.
// C# public OracleBFile GetOracleBFile(int index);
The OracleBFile value of the column.
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.
IsDBNull should be called to check for NULL values before calling this method.
This method returns an OracleBinary structure of the specified column.
// C# public OracleBinary GetOracleBinary(int index);
The OracleBinary value of the column.
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.
IsDBNull should be called to check for NULL values before calling this method.
GetOracleBinary is used on the following Oracle types:
This method returns an OracleBlob object of the specified BLOB column.
// C#public OracleBlob GetOracleBlob(intindex);
The OracleBlob value of the column.
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.
IsDBNull should be called to check for NULL values before calling this method.
GetOracleBlobForUpdate returns an updatable OracleBlob object of the specified BLOB column.
This method returns an updatable OracleBlob object of the specified BLOB column.
This method returns an updatable OracleBlob object of the specified BLOB column using a WAIT clause.
This method returns an updatable OracleBlob object of the specified BLOB column.
// C#public OracleBlob GetOracleBlobForUpdate(intindex);
An updatable OracleBlob object.
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.
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.
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(); }
This method returns an updatable OracleBlob object of the specified BLOB column using a WAIT clause.
// C#public OracleBlob GetOracleBlobForUpdate(intindex, int wait);
An updatable OracleBlob object.
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.
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:
0
"NOWAIT" is appended at the end of a SELECT..FOR UPDATE statement. The statement executes immediately whether the lock is acquired or not. If the lock is not acquired, an exception is thrown.
n
"WAIT n" is appended at the end of a SELECT..FOR UPDATE statement. The statement executes as soon as the lock is acquired. However, if the lock cannot be acquired by n seconds, this method call throws an exception.
The WAIT n" feature is only available for Oracle9i or later. For any version below Oracle9i, n is implicitly treated as -1 and nothing is appended at the end of a SELECT..FOR UPDATE statement.
-1
Nothing is appended at the end of the SELECT..FOR UPDATE. The statement execution waits indefinitely until a lock can be acquired.
The GetOracleBlobForUpdate methods are comparable. See "Example" for a code example demonstrating usage.
This method returns an OracleClob object of the specified CLOB column.
// C#public OracleClob GetOracleClob(intindex);
The OracleClob value of the column.
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.
IsDBNull should be called to check for NULL values before calling this method.
GetOracleClobForUpdate returns an updatable OracleClob object of the specified CLOB column.
This method returns an updatable OracleClob object of the specified CLOB column.
This method returns an updatable OracleClob object of the specified CLOB column using a WAIT clause.
This method returns an updatable OracleClob object of the specified CLOB column.
// C# public OracleClob GetOracleClobForUpdate(int index);
An updatable OracleClob.
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.
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.
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(); }
This method returns an updatable OracleClob object of the specified CLOB column using a WAIT clause.
// C# public OracleClob GetOracleClobForUpdate(int index, int wait);
An updatable OracleClob.
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.
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:
0
"NOWAIT" is appended at the end of a SELECT..FOR UPDATE statement. The statement executes immediately whether the lock is acquired or not. If the lock is not acquired, an exception is thrown.
n
"WAIT n" is appended at the end of a SELECT..FOR UPDATE statement. The statement executes as soon as the lock is acquired. However, if the lock cannot be acquired by n seconds, this method call throws an exception.
The WAIT n" feature is only available for Oracle9i or later. For any version below Oracle9i, n is implicitly treated as -1 and nothing is appended at the end of a SELECT..FOR UPDATE statement.
-1
Nothing is appended at the end of the SELECT..FOR UPDATE. The statement execution waits indefinitely until a lock can be acquired.
IsDBNull should be called to check for NULL values before calling this method.
The GetOracleClobForUpdate methods are comparable. See "Example" for a code example demonstrating usage.
This method returns an OracleDate structure of the specified DATE column.
// C# public OracleDate GetOracleDate(int index);
The OracleDate value of the column.
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.
IsDBNull should be called to check for NULL values before calling this method.
This method returns an OracleDecimal structure of the specified NUMBER column.
// C# public OracleDecimal GetOracleDecimal(int index);
The OracleDecimal value of the column.
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.
IsDBNull should be called to check for NULL values before calling this method.
This method returns an OracleIntervalDS structure of the specified INTERVAL DAY TO SECOND column.
// C# public OracleIntervalDS GetOracleIntervalDS(int index);
The OracleIntervalDS value of the column.
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.
IsDBNull should be called to check for NULL values before calling this method.
This method returns an OracleIntervalYM structure of the specified INTERVAL YEAR TO MONTH column.
// C# public OracleIntervalYM GetOracleIntervalYM(int index);
The OracleIntervalYM value of the column.
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.
IsDBNull should be called to check for NULL values before calling this method.
This method returns an OracleString structure of the specified column. The string is stored as a Unicode string.
// C# public OracleString GetOracleString(int index);
The OracleString value of the column.
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.
IsDBNull should be called to check for NULL values before calling this method.
GetOracleString is used on the following Oracle column types:
This method returns an OracleTimeStamp structure of the Oracle TimeStamp column.
// C# public OracleTimeStamp GetOracleTimeStamp(int index);
The OracleTimeStamp value of the column.
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.
GetOracleTimeStamp is used with the Oracle Type TimeStamp.
IsDBNull should be called to check for NULL values before calling this method.
This method returns an OracleTimeStampLTZ structure of the specified Oracle TimeStamp WITH LOCAL TIME ZONE column.
// C# public OracleTimeStampLTZ GetOracleTimeStampLTZ(int index);
The OracleTimeStampLTZ value of the column.
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.
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.
This method returns an OracleTimeStampTZ structure of the specified Oracle TimeStamp WITH TIME ZONE column.
// C# public OracleTimeStampTZ GetOracleTimeStampTZ(int index);
The OracleTimeStampTZ value of the column.
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.
Used with the Oracle Type TimeStamp with Local Time Zone columns
IsDBNull should be called to check for NULL values before calling this method.
This method returns the specified column value as a ODP.NET type.
// C# public object GetOracleValue(int index);
The value of the column as an ODP.NET type.
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.
This method gets all the column values as ODP.NET types.
// C# public int GetOracleValues(object[] values);
The number of ODP.NET types in the values array.
InvalidOperationException - The connection is closed, the reader is closed, Read() has not been called, or all rows have been read.
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.
This method returns the 0-based ordinal (or index) of the specified column name.
// C# public int GetOrdinal(string name);
The index of the column.
IDataRecord
InvalidOperationException - The reader is closed.
IndexOutOfRangeException - The column index is invalid.
A case-sensitive search is made to locate the specified column by its name. If this fails, then a case-insensitive search is made.
This method returns a DataTable that describes the column metadata of the OracleDataReader.
// C#
public DataTable GetSchemaTable();
A DataTable that contains the metadata of the result set.
IDataReader
InvalidOperationException - The connection is closed or the reader is closed.
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.
| Name | Name Type | Description |
|---|---|---|
|
|
|
The name of the column. |
|
|
|
The |
|
|
|
The maximum possible length of a value in the column.
See "IsByteSemantic" for more information. |
|
|
|
The maximum precision of the column, if the column is a numeric datatype.
This column has valid values for Oracle |
|
|
|
This column has valid values for Oracle |
|
|
|
Indicates whether the column is unique. |
|
|
|
Indicates whether the column is a key column. |
|
|
|
|
|
|
|
The name of the column in the database if an alias is used for the column. |
|
|
|
The name of the schema in the database that contains the column. |
|
|
|
The name of the table or view in the database that contains the column. |
|
|
|
Maps to the common language runtime type. |
|
|
|
The database column type ( |
|
|
|
|
|
|
|
|
|
|
|
This value is always |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
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"]); ..... }
This method returns the string value of the specified column.
// C# public string GetString(int index);
The string value of the column.
IDataRecord
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.
IsDBNull should be called to check for NULL values before calling this method.
This method returns the TimeSpan value of the specified INTERVAL DAY TO SECOND column.
// C# public TimeSpan GetTimeSpan(int index);
The TimeSpan value of the column.
IDataRecord
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.
IsDBNull should be called to check for NULL values before calling this method.
This method returns the column value as a .NET type.
// C# public object GetValue(int index);
The value of the column as a .NET type.
IDataRecord
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.
This method gets all the column values as .NET types.
// C# public int GetValues(object[ ] values);
The number of objects in the values array.
IDataRecord
InvalidOperationException - The connection is closed, the reader is closed, Read() has not been called, or all rows have been read.
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.
This method indicates whether the column value is NULL.
// C# public bool IsDBNull(int index);
Returns true if the column is a NULL value; otherwise, returns false.
IDataRecord
InvalidOperationException - The reader is closed, Read() has not been called, or all rows have been read.
IndexOutOfRangeException - The column index is invalid.
This method should be called to check for NULL values before calling the other accessor methods.
The code example for the OracleDataReader class includes the IsDBNull method. See "Example".
This method advances the data reader to the next result set.
// C#
public bool NextResult();
Returns true if another result set exists; otherwise, returns false.
IDataReader
InvalidOperationException - The connection is closed or the reader is closed.
NextResult is used when reading results from stored procedure execution that return more than one result set.
This method reads the next row in the result set.
// C#
public bool Read();
Returns true if another row exists; otherwise, returns false.
IDataReader
InvalidOperationException - The connection is closed or the reader is closed.
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.
The code example for the OracleDataReader class includes the Read method. See "Example".
|
|
![]() Copyright © 2002 Oracle Corporation. All Rights Reserved. |
|