我可以保持SqlDataReader的“活动"状态吗?关闭连接后? [英] Can I keep a SqlDataReader "alive" after closing connection?
问题描述
关闭连接后,是否有任何方法可以访问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
中,然后才能关闭连接.
Is there any way to access a SqlDataReader
after the connection is closed?
Or is there any objects equivalent to SqlDataReader
that I can store the reader into them and process on the objects later?
I'm receiving a pivot dataset from the server, so I can't use normal classes to process this kind of data, my model looks like this :
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;
}
You can't use the DataReader
after the connection is closed, as it needs to use the connection to retrieve the data from the data source.
You need to read the data into a DataSet
, or DataTable
using the Load
method, then you can close the connection.
这篇关于我可以保持SqlDataReader的“活动"状态吗?关闭连接后?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!