数据表与数据集 [英] Datatable vs Dataset
问题描述
我目前使用 DataTable 从我可以在我的代码中使用的数据库中获取结果.
I currently use a DataTable to get results from a database which I can use in my code.
但是,网络上的许多示例都显示使用 DataSet 并通过集合方法访问表.
However, many example on the web show using a DataSet instead and accessing the table(s) through the collections method.
使用 DataSets 或 DataTables 作为 SQL 结果的存储方法在性能方面或其他方面有什么优势吗?
Is there any advantage, performance wise or otherwise, of using DataSets or DataTables as a storage method for SQL results?
推荐答案
这实际上取决于您要带回的数据类型.由于 DataSet(实际上)只是 DataTable 对象的集合,因此您可以将多个不同的数据集返回到一个单一的、因此更易于管理的对象中.
It really depends on the sort of data you're bringing back. Since a DataSet is (in effect) just a collection of DataTable objects, you can return multiple distinct sets of data into a single, and therefore more manageable, object.
在性能方面,与错误"选择 .NET 结构相比,未优化的查询更有可能导致效率低下.至少,这是我的经验.
Performance-wise, you're more likely to get inefficiency from unoptimized queries than from the "wrong" choice of .NET construct. At least, that's been my experience.
这篇关于数据表与数据集的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!