Dataset vs DataReader Please Help

S

Saimvp

Good Day.
Im new in Programming. Please help me about Dataset and Datareader.

I have couple of question.

1. What is the best way to insert/retrieve a data to SQL Server using
Dataset or Datareader with hundreds or thousands records in Windows or Web
Application?

2. In the real world of Data Recording on Database, what is commonly used
Dataset or Datareader?

Thanks and God bless.
 
A

Andy B

Saimvp said:
Good Day.
Im new in Programming. Please help me about Dataset and Datareader.

I have couple of question.

1. What is the best way to insert/retrieve a data to SQL Server using
Dataset or Datareader with hundreds or thousands records in Windows or Web
Application?

I usually create a dataset at design time with all of the tables and
tableAdapters needed for the application. Usually I will make a dataSet for
each specific job that needs to get done. For example, I have one for the
news and another one for events that are listed on our website. I'm not sure
dataReader would be the best fit for hundreds / thousands of records at a
time. I usually stick to dataReaders for super small jobs like dynamically
outputting an xml formatted stream of some kind. When you make a dataSet, it
can have tableAdapters for each dataTable that holds all of the sql queries
needed to access the particular table the queries are related to. For more
about creating dataSets in code, see
http://msdn2.microsoft.com/en-us/library/system.data.dataset.aspx. If you
want to know how to create and manage dataSets in exact detail, there is a
set of good tutorials found at http://www.asp.net/learn/data-access/. They
deal with just about every point of dataSet management and coding you could
probably think of. I think there is around 70-80 of them but don't remember
for sure.
2. In the real world of Data Recording on Database, what is commonly used
Dataset or Datareader?

I would say again, it depends on what you need to use it for. For huge
amounts of data, you might want a dataset to manage it for you. For simple
queries, I just use the dataReader.
 
A

.\\\\axxx

Good Day.
Im new in Programming. Please help me about Dataset and Datareader.

I have couple of question.

1. What is the best way to insert/retrieve a data to SQL Server using
Dataset or Datareader with hundreds or thousands records in Windows or Web
Application?
It depends upon many things. A datareader does not 'contain' the data
- it is a link to the DB, so if you want to persist the data across
layers, for example, you would need to iterate through the data
reader, storing the data in some object (or collection of objects) to
pass back to another layer. DataReaders should be short lived - just
used for getting the data and doing something with it.
DataSets on the other hand actually collect the data into an object,
which itself contains information about the data - and the dataset can
be passed between layers, as it is no longer connected to the DB.
2. In the real world of Data Recording on Database, what is commonly used
Dataset or Datareader?
Both!
In some applications I have passed DataSets between layers, and used
them exclusively; however in others, I have used my own objects, which
are populated using a datareader, and then passed around.
In fact, as far as I understand, a DataSet actually uses a DataReader
internally to 'populate itself'
DataSets, though, have overheads - as much information about the
structure is also contained in the dataset (as well as, potentially,
different versions of each record that has been updated) so, if you
are dealing with a large numnber of records, it can be more efficient
to create your own objects which contain the information you require,
populate them using a datareader, then utilise the objects in the
client facing part of the application, and pass them back to the data
layer for updating.
In a web app, all this will happen at the server side - the objects
(datasets or your own) aren't passed to the user's browser, only data
from them travels this route.
In a windows app, this data may need to be passed over the network to
each client- which can mean that object size is important - which may
move you down the route of using your own objects to transport the
data.
 
S

Saimvp

Hello thank you for your reply Andy B.

I have one question.

What is the best way to create a Dataset? It's thru Coding or Design?

Thanks and God Bless
 
A

Andy B

That depends on the style of programming. I usually like to make mine at
design time with the Visual Studio dataSet wizards so I can cut down on the
code I have to write by han. Especially the project I am working on now.
Actually, I am avoiding dataSets all together with my current project
because they just don't apply at the time. Besides, even if they did make
sense to use, writing custom code for all of the dataSets without the
wizard/designers help, would probably result in thousands of lines of code.
As it is, the smallest dataSet I have is over 600 lines long (the xsd file).
That would probably be my advice... make them at design time (i.e. the
dataSet wizards). Ultamitly, you would want a data access layer where the
data is accessed from the database and temporarly stored somewhere (usually
a dataSet). The data access layer also manipulates the queries in the
dataSet tableAdapters to get the data from the dataSet. Then you would want
a layer for business logic. Objects and types of code that will take the
data from the data access layer, apply certain rules/security checks and so
on that the application would specifically require of the data. Once that
processing is done, it is passed up to the UI. The UI can be a web page
(asp.net) or a WindowsForms application UI (WinForm). It is then visually
formatted and displayed to the user. Look at that Data Access tutorial
series from asp.net website I posted. It will help a huge ton with
understanding dataSets as well as those other ideas I mentioned a minute
ago. If you need anything just write back. If you really get stuck, send me
off list at (e-mail address removed) and I will try and help..
 
S

sloan

I would read this article...twice through..and bookmark it:

http://msdn2.microsoft.com/en-us/library/ms978496.aspx

An IDataReader will give you the best performance. (Provided you close them
when you're done).
DataSets are populated using IDataReaders (internal code you do not
see)...so that should suggest.


I have deferred to using Custom Objects and Custom Collections in recent
years.
See
http://sholliday.spaces.live.com/Blog/cns!A68482B9628A842A!139.entry
and I have a 2.0 version as well.

.......

At the least, I would create STRONG datasets...using the designer tool.
Coding up datasets seems like alot of work for little gain.

However, I would also consider not using datasets as your primary collection
holder. See the msdn2 article above, it has all of the pros and cons of the
different approaches.
 
M

Marc Gravell

2. In the real world of Data Recording on Database, what is commonly used
You might want to add LINQ (or other ORM tools) to that list; although
right now LINQ-to-SQL (or LINQ-to-entities) are looking very attractive
due to the query composability.

Marc
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top