Reference result set by column index in SqlDataReader : SqlDataReader « ADO.Net « C# / CSharp Tutorial

using System;
using System.Data;
using System.Data.SqlClient;

class MainClass
   static void Main(string[] args)
      string connString = "server=(local)\\SQLEXPRESS;database=MyDatabase;Integrated Security=SSPI;";

      string sql = @"select * from employee";

      SqlConnection conn = null;
      SqlDataReader reader = null;

         conn = new SqlConnection(connString);

         SqlCommand cmd = new SqlCommand(sql, conn);
         reader = cmd.ExecuteReader();

         Console.WriteLine("Querying database {0} with query {1}\n", conn.Database, cmd.CommandText);

         while(reader.Read()) {
            Console.WriteLine("{0} | {1}", reader["FirstName"].ToString().PadLeft(10) , reader[1].ToString().PadLeft(10) );
      }catch (Exception e)
         Console.WriteLine("Error: " + e);

32.26.2.Use SQL Server Data Provider
32.26.3.Reference result set by column name in SqlDataReader
32.26.4.Reference result set by column index in SqlDataReader
32.26.5.Ordinal Indexer demo
32.26.6.Use loop to read all data in SqlDataReader
32.26.7.Use SqlDataReader to retrieve data in the resultset
32.26.8.Get data by data type using SqlDataReader
32.26.9.Using a DataReader to read row by row
32.26.10.Updating Data Using CommondBuilder
32.26.11.SqlDataReader: RecordsAffected
32.26.12.Typed Accessors: int, varchar and decimal
32.26.13.SqlDataReader.GetString, GetDateTime to read a table schema
32.26.15.Use indexer to read data
32.26.16.Mapping .NET Data Provider Data Types to .NET Framework Data Types by calling the GetXXX method
32.26.17.Mapping .NET Data Provider Data Types to .NET Framework Data Types by casting
32.26.18.Mapping .NET Data Provider Data Types to .NET Framework Data Types by converting
32.26.19.Retrieving a Result Set Stream Using a DataReader
32.26.20.Retrieves data as native SQL Server types.
32.26.21.Schema Table from SqlDataReader
32.26.22.ResultSet Info
32.26.23.Output fields from DataReader row
32.26.24.Ordinal Indexer
32.26.25.Get the column ordinal for the Phone attribute and use it to output the column
32.26.26.Data Reading with SqlDataReader
32.26.27.Accessing Data Values in a DataReader
32.26.28.DataReader has records using HasRows property
32.26.29.Handle Multiple Results
32.26.30.Determining the Number of Records Returned in a DataReader