DataReader or DataSet when pulling multiple recordsets in ASP.NET(在 ASP.NET 中拉多个记录集时的 DataReader 或 DataSet)
问题描述
我有一个 ASP.NET 页面,其中包含一堆需要填充的控件(例如下拉列表).
I've got an ASP.NET page that has a bunch of controls that need to be populated (e.g. dropdown lists).
我想单次访问数据库并带回多个记录集,而不是为每个控件进行往返.
I'd like to make a single trip to the db and bring back multiple recordsets instead of making a round-trip for each control.
我可以带回一个 DataSet 中的多个表,或者我可以带回一个 DataReader 并使用.NextResult"将每个结果集放入一个自定义业务类中.
I could bring back multiple tables in a DataSet, or I could bring back a DataReader and use '.NextResult' to put each result set into a custom business class.
我是否会看到使用 DataReader 方法获得足够大的性能优势,还是应该只使用 DataSet 方法?
Will I likely see a big enough performance advantage using the DataReader approach, or should I just use the DataSet approach?
任何您通常如何处理此问题的示例将不胜感激.
Any examples of how you usually handle this would be appreciated.
推荐答案
- 如果您有超过 1000 条记录要从您的数据库中获取.
- 如果你不是很感兴趣自定义存储和自定义分页"对于 GridView"
- 如果您的服务器有内存压力.
- 如果连接没有问题每次该页面时您的数据库调用.
- If you have more than 1000 record to bring from your DataBase.
- If you are not very interested with custom storing and custom paging "For GridView"
- If your server have a memory stress.
- If there is no problem to connect to your DataBase every time that page called.
那我觉得用DataReader比较好.
其他
- 如果您从数据库中获取的记录少于 1000 个.
- 如果您对存储和分页对于GridView"
- 如果您的服务器没有内存压力.
- 如果您想连接到您的数据库只需一次并获取缓存的好处.
- If you have less than 1000 record to bring from your DataBase.
- If you are interested with storing and paging "For GridView"
- If your server haven't a memory stress.
- If you want to connect to your DataBase just one time and get the benefits of Caching.
那我觉得用DataSet比较好.
我认为我是对的.
这篇关于在 ASP.NET 中拉多个记录集时的 DataReader 或 DataSet的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:在 ASP.NET 中拉多个记录集时的 DataReader 或 DataSet


基础教程推荐
- 是否可以在 asp classic 和 asp.net 之间共享会话状态 2022-01-01
- 在 VS2010 中的 Post Build 事件中将 bin 文件复制到物 2022-01-01
- 经典 Asp 中的 ResolveUrl/Url.Content 等效项 2022-01-01
- 错误“此流不支持搜索操作"在 C# 中 2022-01-01
- 将事件 TextChanged 分配给表单中的所有文本框 2022-01-01
- 如何动态获取文本框中datagridview列的总和 2022-01-01
- JSON.NET 中基于属性的类型解析 2022-01-01
- 首先创建代码,多对多,关联表中的附加字段 2022-01-01
- 全局 ASAX - 获取服务器名称 2022-01-01
- 从 VS 2017 .NET Core 项目的发布目录中排除文件 2022-01-01