?
Solved

DataReader Vs DataView

Posted on 2009-07-09
6
Medium Priority
?
1,651 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
What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

 
LVL 20

Accepted Solution

by:
ddayx10 earned 2000 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

Want to be a Web Developer? Get Certified Today!

Enroll in the Certified Web Development Professional course package to learn HTML, Javascript, and PHP. Build a solid foundation to work toward your dream job!

Question has a verified solution.

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

In an ASP.NET application, I faced some technical problems. In this article, I list them out and show the solutions that I found.  I hope it will be useful. Problem: After closing a pop-up window, the parent page should be refreshed automaticall…
A quick way to get a menu to work on our website, is using the Menu control and assign it to a web.sitemap using SiteMapDataSource. Example of web.sitemap file: (CODE) Sample code to add to the page menu: (CODE) Running the application, we wi…
This tutorial will teach you the special effect of super speed similar to the fictional character Wally West aka "The Flash" After Shake : http://www.videocopilot.net/presets/after_shake/ All lightning effects with instructions : http://www.mediaf…
In this video, Percona Solutions Engineer Barrett Chambers discusses some of the basic syntax differences between MySQL and MongoDB. To learn more check out our webinar on MongoDB administration for MySQL DBA: https://www.percona.com/resources/we…
Suggested Courses
Course of the Month10 days, 19 hours left to enroll

770 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