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# 从 List<List<int>> 中删除重 2022-01-01
- 当值可以是对象或空数组时反序列化 JSON 2022-01-01
- 我应该在后面的代码中直接使用 Linq To SQL 还是使 2022-01-01
- Moq It.Is<>不匹配 2022-01-01
- WPF 模态进度窗口 2022-01-01
- .NET SerialPort DataReceived 事件未触发 2022-01-01
- 禁止输入少量字符,例如'<'、'&a 2022-01-01
- 如何使用 .Net 检查 Active Directory 服务器是否已启动并正在运行? 2022-01-01
- Azure Functions:CosmosDBTrigger 未在 Visual Studio 中触发 2022-01-01
- 如果有人提交恶意软件Nuget包怎么办? 2022-01-01
