SqlDataReader : SqlDataReader : ADO.Net C# Examples


C# Examples » ADO.Net » SqlDataReader »

 

SqlDataReader









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

class  MainClass
{
    [STAThread]
    static  void  Main(string[]  args)
    {
        string  ConnectionString  ="server=(local)\\SQLEXPRESS;database=MyDatabase;Integrated  Security=SSPI;";
        string  SQL  =  "SELECT  *  FROM  Employee";

        SqlConnection  conn  =  new  SqlConnection(ConnectionString);
        SqlCommand  cmd  =  new  SqlCommand(SQL,  conn);
                
        conn.Open();
        SqlDataReader  reader  =  cmd.ExecuteReader();
        Console.WriteLine("ID,  FirstName");

        while  (reader.Read())
        {
            Console.Write(reader["ID"].ToString()  +  ",  ");
            Console.Write(reader["FirstName"].ToString()  +  ",  ");
        }
        reader.Close();
        conn.Close();
    }
}
    
   
  
   




HTML code for linking to this page:

Follow Navioo On Twitter

C# Examples

 Navioo ADO.Net
» SqlDataReader