我可以保持SqlDataReader的“活动"状态吗?关闭连接后? [英] Can I keep a SqlDataReader "alive" after closing connection?

查看:121
本文介绍了我可以保持SqlDataReader的“活动"状态吗?关闭连接后?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

关闭连接后,是否有任何方法可以访问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方法将数据读取到DataSetDataTable中,然后才能关闭连接.

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屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆