Using a DataReader to read row by row : SqlDataReader : ADO.Net C# Examples


C# Examples » ADO.Net » SqlDataReader »

 

Using a DataReader to read row by row









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

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

        MyConnection.Open();

        SqlCommand  MyCommand  =  new  SqlCommand("SELECT  *  FROM  Employee",  MyConnection);
        SqlDataReader  MyDataReader  =  MyCommand.ExecuteReader(CommandBehavior.CloseConnection);

        while  (MyDataReader.Read())
        {
            Console.WriteLine(MyDataReader[0]  +  "  "  +  MyDataReader[1]);
        }

        MyConnection.Close();
    }
}
    
   
  
   




HTML code for linking to this page:

Follow Navioo On Twitter

C# Examples

 Navioo ADO.Net
» SqlDataReader