DataSet or DataReader?
发表于2004/10/16 13:14:00 613人阅读
The DataSet, on the other hand, is a great way to hold data from the database, but filling it comes with a performance penalty. If you need to manipulate your data and save it back to the database, the DataSet is really the only game in town. Using the DataSet to simply report on data (like on a Web page, for instance) usually is the wrong approach. I say "usually" because there are always exceptions to this rule.
Let's look at a specific domain problem: an e-commerce site. Assuming we have a large number of salable items, I would use DataReaders to show the user the products they are looking for and a DataSet for the shopping basket. When you list products by caching all the items in your catalog, you usually lose efficiency when the cache is too large. I usually like to let the database handle the caching of recently used items. It does a better job in most cases. But a smaller DataSet to contain the user's information and shopping basket could be cached in the Web session so that we can limit the number of database reads and writes. If the visitor never ends up buying anything, their shopping basket could simply disappear (and never get persisted) when his or her session dies.
Just remember this caveat: If you need it cached, use a DataSet; if you need it once, use a DataReader.
lijingrong_ljr 2015-08-07 15:25 413
Name_G2T14_8 2011-07-10 10:51 587
ygzhong000 2014-05-17 17:30 544
changwei07080 2012-08-03 13:44 1443
SmallXianNotImmortal 2016-01-15 10:35 275
stypace 2013-08-29 22:12 1286
a313976010 2011-09-05 15:54 331
DataSet DataTable DataReader dataAdapter区别
handthing 2011-03-24 13:54 368