Link to home
Start Free TrialLog in
Avatar of dennisdominic
dennisdominicFlag for Hong Kong

asked on

DataReader Vs DataView

(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?
Avatar of Member_2_4913559
Member_2_4913559
Flag of United States of America image

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.


???
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
Avatar of dennisdominic

ASKER

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.
https://www.experts-exchange.com/questions/20614250/Compact-Framework-DataSets-DataTables-DataGrids.html?query=DataSet+DataTable+DataView&clearTAFilter=true 
ASKER CERTIFIED SOLUTION
Avatar of Member_2_4913559
Member_2_4913559
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
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.
very comprehensive.. more than I can digest, but I guess I need to try it out to understand. Thanks.