Solved

DataReader Vs DataView

Posted on 2009-07-09
6
1,574 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
  • 3
  • 2
6 Comments
 
LVL 20

Expert Comment

by:ddayx10
Comment Utility
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
Comment Utility
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
Comment Utility
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
How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

 
LVL 20

Accepted Solution

by:
ddayx10 earned 500 total points
Comment Utility
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
Comment Utility
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
Comment Utility
very comprehensive.. more than I can digest, but I guess I need to try it out to understand. Thanks.
0

Featured Post

Find Ransomware Secrets With All-Source Analysis

Ransomware has become a major concern for organizations; its prevalence has grown due to past successes achieved by threat actors. While each ransomware variant is different, we’ve seen some common tactics and trends used among the authors of the malware.

Join & Write a Comment

Just a quick little trick I learned recently.  Now that I'm using jQuery with abandon in my asp.net applications, I have grown tired of the following syntax:      (CODE) I suppose it just offends my sense of decency to put inline VBScript on a…
IntroductionWhile developing web applications, a single page might contain many regions and each region might contain many number of controls with the capability to perform  postback. Many times you might need to perform some action on an ASP.NET po…
When you create an app prototype with Adobe XD, you can insert system screens -- sharing or Control Center, for example -- with just a few clicks. This video shows you how. You can take the full course on Experts Exchange at http://bit.ly/XDcourse.
This video explains how to create simple products associated to Magento configurable product and offers fast way of their generation with Store Manager for Magento tool.

762 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

Need Help in Real-Time?

Connect with top rated Experts

12 Experts available now in Live!

Get 1:1 Help Now