有什么方法可以在连接关闭后访问 SqlDataReader
吗?
或者是否有任何等效于 SqlDataReader
的对象,我可以将读取器存储到其中并稍后处理这些对象?
我正在从服务器接收数据透视数据集,所以我不能使用普通类来处理这种数据,我的模型如下所示:
public class OneToNinetyNine
{
public List<Cities> listCities;
public string CityID;
public DateTime DateFrom;
public DateTime DateTo;
// this is the reader that I attempt to pass to the views
public SqlDataReader SqlReader;
}
最佳答案
DataReader
在连接关闭后不能使用,因为它需要使用连接从数据源中检索数据。
您需要使用Load
方法将数据读入DataSet
或DataTable
,然后您可以关闭连接。
关于c# - 我可以在关闭连接后保留 SqlDataReader "alive"吗?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/26797839/