Solved

DataReader Vs DataView

Posted on 2009-07-09
6
1,617 Views
Last Modified: 2012-05-07
(OleDbDataReader Vs SqlDataReader)

What are the main differences between DataReader   Vs   DataView  ?

Can I perform a Filter on DataReader? I have a list of 1000 records that I need to perform multiple Filters on a Loop. Would DataView be faster?
0
Comment
Question by:dennisdominic
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 3
  • 2
6 Comments
 
LVL 20

Expert Comment

by:ddayx10
ID: 24820287
You probably want to use DataView for this operation.

In a datareader you basically get one shot at the data. You open a connection, feed it a query, the results are returned one line at a time through the datareader. As you read a line you can check values, store them somewhere, do whatever with that one line, but you only have access to that particular row. You can build an object like a table or list or even just plug the datareader in as the datasource for an object like a gridview. You cannot perform a filter straight on the datareader because you only have access to one row at a time. You could however make an object with a reader and manipulate it after the reader was finished.

A DataView is going to store the entire query results in it's entirety. You can manipulate it over and over getting the various results you want. The only slight disadvantage would be that this is a larger object (obviously) and so uses a bit more resources. I wouldn't think that would affect your consideration here. The DataView is made for what you are trying to do.

I would use the datareader if I was binding to an object and modifying objects in its databound event per se. If I wanted to manipulate the data and bind it to several objects based on the filter I gave it I would use the dataview instead of having to query the database multiple times.


???
0
 
LVL 2

Expert Comment

by:lppperes
ID: 24820315
Hi dennisdominic,
In first place, DataReader is a specialized class that you found in each data provider, and DataView is a generic class to hold data in memory.
Operations like filter and sort are only possible in DataView.
Take a look at this forum. I think it may help you.
http://www.velocityreviews.com/forums/t86413-dataview-vs-datareader.html
0
 
LVL 1

Author Comment

by:dennisdominic
ID: 24820686
I'm going to award points, but am I correct to say...
DataReader - a specialized class just for reading data, forward only, and mainly used for populating objects such as gridview.
DataTable - a table that resides in the memory.
DataView - used to represent a subset of data from a DataTable. In order to use DataView, I need to run it against a DataTable?
DataSet - a collection of DataTable.
More information here.
http://www.experts-exchange.com/Programming/Languages/.NET/Q_20614250.html?query=DataSet+DataTable+DataView&clearTAFilter=true 
0
PeopleSoft Has Never Been Easier

PeopleSoft Adoption Made Smooth & Simple!

On-The-Job Training Is made Intuitive & Easy With WalkMe's On-Screen Guidance Tool.  Claim Your Free WalkMe Account Now

 
LVL 20

Accepted Solution

by:
ddayx10 earned 500 total points
ID: 24820877
Award points not important...was a simple question just threw my $.02 at... looks like you have a better summary than any given :)

I would make sure you weren't confused about your summation of DataView. I would just say that yes you use a DataTable to create a DataView, but once it's created you don't need the table anymore and can filter the DataView in a myriad of ways. So you don't need the table as a seperate entity anymore.

Here is an example of where I made a DataView (for someone else's needs) and they wanted to just keep the DataView in session and use it again later for sorting, and re-binding.
http://www.experts-exchange.com/Programming/Languages/.NET/ASP.NET/Q_24534302.html

http://msdn.microsoft.com/en-us/library/system.data.dataset.aspx
DataSet: Collection of DataTable objects. In memory. Can perform relational queries against tables inside DataSet.

http://msdn.microsoft.com/en-us/library/system.data.datatable.aspx
DataTable: In memory representation of a dbo or other table. Can filter into an array using select method. Interestingly can use a datareader to read. Also used to make a dataview.

http://msdn.microsoft.com/en-us/library/system.data.dataview.aspx
DataView: Used to create a customized view of a DataTable. Has methods and properties for filtering of that DataTable.

There's $.02 more cents worth :)
0
 
LVL 20

Expert Comment

by:ddayx10
ID: 24820884
I would mention to look at the menu on the left for those links. You will be able to look at the properties, methods, and events for these object. Even a quick glance through them can be pretty enlightening.
0
 
LVL 1

Author Closing Comment

by:dennisdominic
ID: 31601935
very comprehensive.. more than I can digest, but I guess I need to try it out to understand. Thanks.
0

Featured Post

Free Tool: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Today is the age of broadband.  More and more people are going this route determined to experience the web and it’s multitude of services as quickly and painlessly as possible. Coupled with the move to broadband, people are experiencing the web via …
The ECB site provides FX rates for major currencies since its inception in 1999 in the form of an XML feed. The files have the following format (reducted for brevity) (CODE) There are three files available HERE (http://www.ecb.europa.eu/stats/exch…
In an interesting question (https://www.experts-exchange.com/questions/29008360/) here at Experts Exchange, a member asked how to split a single image into multiple images. The primary usage for this is to place many photographs on a flatbed scanner…

737 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question