在 ASP.NET 中拉多个记录集时的 DataReader 或 DataSet多个、记录集、NET、ASP

2023-09-06 14:01:55 作者:情深不及久伴i

我有一个 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比较好.

我认为我是对的.