12. Understanding .NET Data Provider Connectivity : IngresDataReader Object--Retrieve Data from the Database : Example: Using the IngresDataReader
 
Share this page                  
Example: Using the IngresDataReader
The following is an implementation of IngresDataReader.
static void DataReaderDemo(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();
}