c# - 我可以在关闭连接后保留 SqlDataReader "alive"吗?

标签 c# asp.net-mvc dynamic 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,然后您可以关闭连接。

关于c# - 我可以在关闭连接后保留 SqlDataReader "alive"吗?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/26797839/

相关文章:

C#、MVC 确认删除对话框

HTML 敏捷包解析

c - C realloc() 错误中的动态数组

c# - C++ 从 C# COM DLL 调用函数

c# - 将 Rx 聚合保存到局部变量

c# - 从 Entity Framework 中自动生成的类继承

scala - 如何使用特征聚合 akka-http 路由?

c# - 等待事件从任务列表中触发

c# - 如何使用 C# 在 MVC 布局 View 中编辑 CSS 类

c# - 方法中动态方法返回值的显式转换不允许调用扩展方法