title: Return datetime from stored procedure
body: <p>I have this query:</p>
  
  <pre><code>CREATE PROCEDURE [dbo].[spGetWhenTaskLastRun]   
      @dt datetime out         
  AS
  BEGIN
      SELECT  
          @dt = whenTaskLastRan
      FROM
          [dbo].[t_whenTaskLastRan]   
  END
  </code></pre>
  
  <p>and this C# code to execute this query:</p>
  
  <pre><code>SqlDataReader reader;
  
  string ConnectionString = SafaConnectionString.ConnectionString;
  
  SqlConnection Connection = new SqlConnection(ConnectionString);
  
  SqlCommand cmd = new SqlCommand("spGetWhenTaskLastRun", Connection);
  cmd.CommandType = CommandType.StoredProcedure;
  cmd.Parameters.Add("@dt", SqlDbType.DateTime);
  cmd.Parameters["@dt"].Direction = ParameterDirection.Output;
  
  try
  {
      Connection.Open();
      reader = cmd.ExecuteReader();
  
      if (reader.HasRows)
          return (DateTime)cmd.Parameters["@dt"].Value;
      else
          return DateTime.Now;
  }
  </code></pre>
  
  <p>but it always returns <code>reader.HasRows = false</code> and no records.</p>
  
  <p>Have I got the query wrong?</p>