9. Understanding .NET Data Provider Connectivity : .NET Data Provider Classes : IngresDataReader Class
 
Share this page                  
IngresDataReader Class
IngresDataReader provides a means of reading a forward-only stream of rows from a result-set created by a SELECT query or a row-producing database procedure.
When an IngresDataReader is open, the IngresConnection is busy and no other operations are allowed on the IngresConnection (other than IngresConnection.Close) until IngresDataReader.Close is issued. Created by the IngresCommand.ExecuteReader methods.
IngresDataReader Class Declaration
The IngresDataReader can be declared as follows:
C#: public sealed class IngresDataReader : System.Data.Common.DbDataReader
VB.NET: NotInheritable Public Class IngresDataReader
Inherits System.Data.Common.DbDataReader
IngresDataReader Class Example
The following is an example implementation of the IngresDataReader class:
static void ReaderDemo(string connstring)
{
    IngresConnection conn = new IngresConnection(connstring);
 
    string strNumber;
    string strName;
    string strSSN;
 
    conn.Open();
 
    IngresCommand cmd = new IngresCommand(
        "select number, name, ssn from personnel", conn);
 
    IngresDataReader reader = cmd.ExecuteReader();
 
    Console.Write(reader.GetName(0) + "\t");
    Console.Write(reader.GetName(1) + "\t");
    Console.Write(reader.GetName(2));
    Console.WriteLine();
 
    while (reader.Read())
    {
        strNumber= reader.IsDBNull(0)?
            "<none>":reader.GetInt32(0).ToString();
        strName = reader.IsDBNull(1)?
            "<none>":reader.GetString(1);
        strSSN = reader.IsDBNull(2)?
            "<none>":reader.GetString(2);
 
        Console.WriteLine(
        strNumber + "\t" + strName + "\t" + strSSN);
    }
 
    reader.Close();
    conn.Close();
}
IngresDataReader Class Properties
The IngresDataReader class contains the following properties:
Property
Accessor
Description
Depth
get
The depth of nesting for the current row. This data provider always returns a depth of zero to indicate no nesting of tables.
FieldCount
get
The number of columns in the current row.
HasRows
get
Returns true if the data reader contains one or more rows. Returns false if the data reader contains zero rows.
IsClosed
get
A true/false indicator as to whether the data reader is closed.
Item
get
Gets the column value in its native format for a given column name or column ordinal. This property is the C# indexer for the IngresDataReader class.
RecordsAffected
get
The number of rows updated, inserted, or deleted by execution of the SQL statement. -1 is returned for SELECT statements.
IngresDataReader Class Public Methods
The public methods available to the IngresDataReader class are:
Method
Description
Close
Closes the IngresDataReader.
GetBoolean
Gets the column value as a Boolean.
GetByte
Gets the column value as an unsigned 8-bit Byte.
GetBytes
Gets the column value as a byte stream into a Byte array.
GetChar
Gets the column value as a Char.
GetChars
Gets the column value as a character stream into a Char array.
GetDataTypeName
Gets the column's data type name as known in Ingres.
GetDateTime
Gets the column value as a DateTime.
GetDecimal
Gets the column value as a Decimal.
GetDouble
Gets the column value as a double.
GetFieldType
Gets the column's .NET Type.
GetFloat
Gets the column value as a Float.
GetGuid
Gets the column value as a Guid.
GetInt16
Gets the column value as a signed 16-bit integer.
GetInt32
Gets the column value as a signed 32-bit integer.
GetInt64
Gets the column value as a signed 64-bit integer.
GetName
Gets the column's name using a specified ordinal.
GetOrdinal
Gets the column's ordinal using a specified name.
GetSchemaTable
Returns a DataTable that describes the resultset column metadata. If ExecuteReader( CommandBehavior.KeyInfo ) was called, additional information about primary key columns, unique columns, and base names is retrieved from the database catalog and included in the returned DataTable. For column information returned, see GetSchemaTable Columns Returned.
GetString
Gets the column value as a string.
GetTimeSpan
Gets the column value as a TimeSpan.
GetValue
Gets the column value in its native format.
GetValues
Gets all of the column values into an Object array.
IsDBNull
Returns true/false indicating whether the column value is null.
NextResult
Advances the data reader to the next result set if present.
Read
Advances the data reader to the next row in the result set.
Important!  There are no conversions performed by the GetXXX methods. If the data is not of the correct type, an InvalidCastException is thrown.
Always call IsDBNull on a column if there is any chance of it being null before attempting to call one of the GetXXX accessor to retrieve the data.
GetSchemaTable Columns Returned
The GetSchemaTable describes the column metadata of the IngresDataReader.
Note:  The column information is not necessarily returned in the order shown.
Column Information
Data Type
Description
ColumnName
String
The name of the column, which reflects the renaming of the column in the command text (that is, the alias).
ColumnOrdinal
Int32
The number of the column, beginning with 1.
ColumnSize
Int32
Maximum possible length of a value in the column.
NumericPrecision
Int16
This is the maximum precision of the column if the column is a numeric data type; otherwise the value is null.
NumericScale
Int16
This is the number of decimal places in the column if the column is a numeric data type; otherwise the value is null.
DataType
Type
The .NET Framework data type of the column.
ProviderType
IngresType
The indicator of the column's data type
IsLong
Boolean
Set to true if the column contains a long varchar, long varbinary, or long nvarchar object; otherwise false.
AllowDBNull
Boolean
Set to true if the application can set the column to a null value or if the data provider cannot determine if the application can set the column to a null value. Set to false if it is known that the application is not permitted to set the column to a null. Note that a column value may be null even if the application is not permitted to set the null value.
IsReadOnly
Boolean
Set to true if it is known that the column cannot be modified; otherwise false.
IsRowVersion
Boolean
Set to true if column has a persistent row identifier that cannot be written to and serves only to identify the row. The .NET Data Provider always returns false.
IsUnique
Boolean
Set to true if no two rows in the table can have the same value in this column. Set to false if not unique or if uniqueness cannot be determined. Only set if ExecuteReader(CommandBehavior.KeyInfo) was called.
IsKey
Boolean
Set to true if this column is in the set of columns that, taken together, uniquely identify the row. Only set if ExecuteReader( CommandBehavior.KeyInfo ) was called.
IsAutoIncrement
Boolean
Set to true if the column assigns values to new rows in fixed increments. The .NET Data Provider always returns false.
BaseCatalogName
String
The name of the database catalog that contains the column. This value is null if the catalog name cannot be determined. The .NET Data Provider always returns a null value.
BaseSchemaName
String
The name of the database schema that contains the column. This value is null if the schema name cannot be determined. Only set if ExecuteReader(CommandBehavior.KeyInfo) was called.
BaseTableName
String
The name of the database table or view that contains the column. This value is null if the table name cannot be determined. Only set if ExecuteReader(CommandBehavior.KeyInfo) was called.
BaseColumnName
String
The name of the column in the database. This value is null if the column name cannot be determined. Only set if
ExecuteReader( CommandBehavior.KeyInfo ) was called.
Mapping of Ingres Native Types to .NET Types
The following table maps the native Ingres database types supported by the .NET Data Provider to their corresponding .NET type. It also maps the typed accessor that a .NET application uses for an Ingres native database type to be obtained as a .NET type.
IngresType
Ingres Data Type
.NET Data Type
Accessor
Binary
byte
Byte[]
GetBytes()
Char
char
String
GetString()
DateTime
date
DateTime
GetDateTime()
Decimal
decimal
Decimal
GetDecimal()
Double
double precision
(float8)
Double
GetDouble()
SmallInt
smallint
Int16
GetInt16()
TinyInt
integer1
Byte
GetByte()
Int
integer
Int32
GetInt32()
BigInt
bigint
Int64
GetInt64()
LongVarBinary
long byte
Byte[]
GetBytes()
LongVarChar
long varchar
String
GetString()
LongNVarChar
long nvarchar
String
GetString()
Nchar
nchar
String
GetString()
NvarChar
nvarchar
String
GetString()
Real
real (float4)
Single
GetString()
VarBinary
byte varying
Byte[]
GetBytes()
VarChar
varchar
String
GetString()
IntervalYearToMonth
interval year to month
String
GetString()
IntervalDayToSecond
interval day to second
Timespan
GetTimeSpan()