title: Return datareader from method
body: <p>I have the following method </p>
  
  <pre><code>    public static SqlDataReader MenuDataReader(string url)
      {
          using (SqlConnection con = new SqlConnection(connectionString))
          {
              using (SqlCommand cmd = new SqlCommand("spR_GetChildMenus", con))
              {
                  cmd.CommandType = CommandType.StoredProcedure;
                  cmd.Parameters.AddWithValue("@PageUrl", url);
                  cmd.Parameters.AddWithValue("@MenuId", ParameterDirection.Output);
                  cmd.Parameters.AddWithValue("@ParentId", ParameterDirection.Output);
                  cmd.Parameters.AddWithValue("@TitleText", ParameterDirection.Output);
                  cmd.Parameters.AddWithValue("@ExternalUrl", ParameterDirection.Output);
                  cmd.Parameters.AddWithValue("@FullUrl", ParameterDirection.Output);
                  cmd.Parameters.AddWithValue("@ChildCount", ParameterDirection.Output);
                  con.Open();
                  SqlDataReader reader = cmd.ExecuteReader();
                  if (reader.HasRows)
                  {
                      //return reader;
  
                      while (reader.Read())
                      {
                          return reader;
                      }
  
                  }
              }
          }
          return null;
      }
  </code></pre>
  
  <p>which im calling like this</p>
  
  <pre><code>        SqlDataReader reader = MenuDataReader(url);
          if (reader.HasRows)
          {
              while (reader.Read())
              { }}
  </code></pre>
  
  <p>however im getting the error message </p>
  
  <blockquote>
    <p>Invalid attempt to call HasRows when reader is closed.</p>
  </blockquote>
  
  <p>can anyone help me out </p>
  
  <p>thanks</p>