SqlCommand : SqlCommand : ADO.Net C# Examples


C# Examples » ADO.Net » SqlCommand »

 

SqlCommand









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


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

        conn.Open();
        SqlCommand  cmd  =  new  SqlCommand(  "select  *  from  Employee",  conn  );
        SqlDataReader  rdr  =  cmd.ExecuteReader(  CommandBehavior.CloseConnection  );

        while  (  rdr.Read()  )
        {
            System.Console.WriteLine(  "{0}",  rdr.GetString(  1  )  );
        }

        rdr.Close();
    }
}
    
   
  
   




HTML code for linking to this page:

Follow Navioo On Twitter

C# Examples

 Navioo ADO.Net
» SqlCommand