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


- 在哪里可以找到使用中的C#/XML文档注释的好例子? 2022-01-01
- Web Api 中的 Swagger .netcore 3.1,使用 swagger UI 设置日期时间格式 2022-01-01
- WebMatrix WebSecurity PasswordSalt 2022-01-01
- C# 中多线程网络服务器的模式 2022-01-01
- 带有服务/守护程序应用程序的 Microsoft Graph CSharp SDK 和 OneDrive for Business - 配额方面返回 null 2022-01-01
- MoreLinq maxBy vs LINQ max + where 2022-01-01
- 输入按键事件处理程序 2022-01-01
- 如何用自己压缩一个 IEnumerable 2022-01-01
- C#MongoDB使用Builders查找派生对象 2022-09-04
- 良好实践:如何重用 .csproj 和 .sln 文件来为 CI 创建 2022-01-01