问题描述
我刚刚看到这个主题:http://stackoverflow.com/questions/2250/datatable-vs-dataset但它并没有解决我的疑问。让我解释好,我是做与数据库的连接,并需要显示的结果在GridView。 (我用的记录集时,我前段时间曾与VB6和DataSet是pretty的相似,它是如此更容易使用的数据集。)然后,一个男人对我说的DataSet是不是做的最好的方法。
I just saw this topic: http://stackoverflow.com/questions/2250/datatable-vs-datasetbut it didn't solve my doubt .. Let me explain better, I was doing connection with database and needed to show the results in a GridView. (I used RecordSet when I worked with VB6 while ago and DataSet is pretty similar to it so was much easier to use DataSet.)Then a guy told me DataSet wasn't the best method to do ..
所以,我应该学习的DataReader或继续使用数据集?数据表?有哪些优点/缺点是什么?
So, should I 'learn' DataReader or keep using DataSet ? DataTable ?What are the pros/cons ?
推荐答案
这要看你的需求。其中最重要的区别是,一个DataReader将保持一个开放连接到数据库,直到你用它做而数据集将是一个在内存中的对象。如果一个控件绑定到一个DataReader那么它仍然是开放的。此外,一个DataReader是正向只阅读方式不能被操纵的数据。随着数据集,你可以来回移动,并为您认为合适的操作数据。
It depends on your needs. One of the most important differences is that a DataReader will retain an open connection to your database until you're done with it while a DataSet will be an in-memory object. If you bind a control to a DataReader then it's still open. In addition, a DataReader is a forward only approach to reading data that can't be manipulated. With a DataSet you can move back and forth and manipulate the data as you see fit.
一些额外的功能:数据集可以被序列化并重新psented在XML $ P $,因此,很容易传递给周围的其他层。的DataReader不能被序列化。
Some additional features: DataSets can be serialized and represented in XML and, therefore, easily passed around to other tiers. DataReaders can't be serialized.
在另一方面,如果你有大量行从数据库中读取,你手头宽裕一些流程的业务规则DataReader对象可能更合理,而不是加载一个DataSet与所有的行,占用内存并有可能影响到可扩展性。
On the other hand if you have a large amount of rows to read from the database that you hand off to some process for a business rule a DataReader may make more sense rather than loading a DataSet with all the rows, taking up memory and possibly affecting scalability.
下面有一个链接,这是一个有点过时,但仍然是有用的:对比的ADO.NET的DataReader和数据集一>
Here's a link that's a little dated but still useful: Contrasting the ADO.NET DataReader and DataSet.
这篇关于什么是更好的:数据集或DataReader的?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!