using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Data;
using System.Data.SqlClient;

namespace ExecuteProcVsCmd
{
    class Program
    {
        static void Main(string[] args)
        {
            using (SqlConnection conn = new SqlConnection("database=AdventureWorks;integrated security=sspi"))
            using (SqlCommand cmd1 = new SqlCommand("dbo.GetOrders", conn))
            using (SqlCommand cmd2 = new SqlCommand("exec dbo.GetOrders @StartOrderDate", conn))
            using (SqlCommand cmd3 = new SqlCommand())
            {
                cmd1.CommandType = CommandType.StoredProcedure;
                cmd2.CommandType = CommandType.Text;
                cmd3.CommandType = CommandType.Text;
                cmd3.Connection = conn;
                cmd3.CommandText = @"
                select * from Sales.SalesOrderHeader h, Sales.SalesOrderDetail d
                WHERE h.SalesOrderID = d.SalesOrderId
                AND h.OrderDate >= @StartOrderDate";

                cmd1.Parameters.Add("@StartOrderDate", SqlDbType.DateTime);
                cmd2.Parameters.Add("@StartOrderDate", SqlDbType.DateTime);
                cmd3.Parameters.Add("@StartOrderDate", SqlDbType.DateTime);

                cmd1.Parameters[0].Value = new DateTime(2004, 07, 31);
                cmd2.Parameters[0].Value = new DateTime(2004, 07, 31);
                cmd3.Parameters[0].Value = new DateTime(2004, 07, 31);

                conn.Open();
                SqlDataReader rdr = null;
                rdr = cmd1.ExecuteReader();
                rdr.Close();
                rdr = cmd2.ExecuteReader();
                rdr.Close();
                rdr = cmd3.ExecuteReader();
                rdr.Close();

            }
        }
    }
}
