Possible Duplicate:
Invalid attempt to call FieldCount when reader is closed
im using asp.net with c#. Im atempting to close the connection on the finally statement on aspx2.cs.
In aspx1.cs:
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();
}
}
In aspx2.cs:
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();
}
When it reaches DataGrid1.DataBind(); on aspx1.cs.
i get error:
"Invalid attempt to FieldCount when reader is closed error"
How to solve this?