title: Will putting a "using" statement around a DataReader close it?
body: <p>I usually write my <code>DataReader</code> code like this:</p>
  
  <pre><code>try
  {
      dr = cmd.ExecuteReader(CommandBehavior.SingleResult);
      while (dr.Read())
      {
          // Do stuff
      }
  }
  finally
  {
      if (dr != null) { dr.Close(); }
  }
  </code></pre>
  
  <p>Is it safe to replace the <code>try</code> and <code>finally</code> with just a <code>using</code> block around the <code>DataReader</code>'s creation? The reason I wonder is because in all the Microsoft examples I've seen they use a using for the connection but always explicitly call <code>Close()</code> on the <code>DataReader</code>.</p>
  
  <p>Heres's an example from
  <a href="http://msdn.microsoft.com/en-us/library/haa3afyz(VS.100).aspx" rel="noreferrer">Retrieving Data Using a DataReader (ADO.NET)</a>:</p>
  
  <pre><code>static void HasRows(SqlConnection connection)
  {
      using (connection)
      {
          SqlCommand command = new SqlCommand(
            "SELECT CategoryID, CategoryName FROM Categories;",
            connection);
          connection.Open();
  
          SqlDataReader reader = command.ExecuteReader();
  
          if (reader.HasRows)
          {
              while (reader.Read())
              {
                  Console.WriteLine("{0}\t{1}", reader.GetInt32(0),
                      reader.GetString(1));
              }
          }
          else
          {
              Console.WriteLine("No rows found.");
          }
          reader.Close();
      }
  }
  </code></pre>