Dataset vs Datareader

One of the most common questions you can ask a programmer is which is faster, a Dataset or Datareader. I was asked this in the past doing interviews and was somewhat puzzled. Thanks to using LINQ to SQL and Entity Framework the inner workings of ADO.NET is hidden.

To be ask which one is quicker is a actually a fairly dumb question, because they work so differently that comparing them in terms of speed does not make sense. I could go into detail myself but there is a post on stackoverflow that uses an excellent analogy to explain the differences between the two.

That is essentially: “which is better: a bucket or a hose?”

A DataSet if the bucket here; it allows you to carry around a disconnected set of data and work with it – but you need to incur the cost of carrying the bucket (so best to keep it to a size you are comfortable with).

A data-reader is the hose: it provides one-way/once-only access to data as it flies past you; you don’t have to carry all of the available water at once, but it needs to be connected to the tap/database.

And in the same way that you can fill a bucket with a hose, you can fill the DataSet with the data-reader.

The point I’m trying to make is that they do different things…

You can read more on the subject on Stackoverflow here.

Advertisements

Published by

Alan Feekery

Developer, Gamer, Musician, Cyclist and big Motorsport fan... enjoys the odd cup of coffee :)

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s