title: asp.net Invalid attempt to FieldCount when reader is closed error
body: <blockquote>
    <p><strong>Possible Duplicate:</strong><br>
    <a href="https://stackoverflow.com/questions/3465490/invalid-attempt-to-call-fieldcount-when-reader-is-closed">Invalid attempt to call FieldCount when reader is closed</a>  </p>
  </blockquote>
  
  
  
  <p>im using asp.net with c#.
  Im atempting to close the connection on the finally statement on aspx2.cs.</p>
  
  <p>In  aspx1.cs:</p>
  
  <pre><code>private void BindDataGrids()
  {
       try
       {
            DataGrid1.DataSource = instance.ShowDifferences(Convert.ToInt32(Request.QueryString
  
  ["CrewId"]), DateTime.Parse(Request.QueryString["StartDate"]), DateTime.Parse(Request.QueryString["EndDate"]));
            DataGrid1.DataBind();
        }
   }
  </code></pre>
  
  <p>In  aspx2.cs:</p>
  
  <pre><code> public static SqlDataReader ShowDifferences(int crewID, DateTime date1, DateTime date2)
   {
        Database db = DatabaseFactory.CreateDatabase();
        string sqlCommand = "stored_procedure";
        DBCommandWrapper command = db.GetStoredProcCommandWrapper(sqlCommand);
        try
        {
  ........code...........
           command.AddInParameter("@EndDate", DbType.Date, date2);
                  IDataReader reader = db.ExecuteReader(command);
           return (SqlDataReader)reader;
        }
        finally
        {
            command.Command.Connection.Close();
        }
  </code></pre>
  
  <p>When it reaches   DataGrid1.DataBind(); on aspx1.cs.</p>
  
  <p>i get error:</p>
  
  <pre><code>"Invalid attempt to FieldCount when reader is closed error"
  </code></pre>
  
  <p>How to solve this?</p>