asp.netをc#で使用しています。aspx2.csのfinallyステートメントで接続を閉じようとしています。
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();
}
}
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();
}
DataGrid1.DataBind();に到達したとき。aspx1.csで。
エラーが発生します:
"Invalid attempt to FieldCount when reader is closed error"
これを解決する方法は?