gpt4 book ai didi

c# - asp.net 阅读器关闭错误时对 FieldCount 的无效尝试

转载 作者:太空宇宙 更新时间:2023-11-03 19:19:11 24 4
gpt4 key购买 nike

<分区>

Possible Duplicate:
Invalid attempt to call FieldCount when reader is closed

我在 c# 中使用 asp.net。我正在尝试关闭 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"

如何解决?

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com