Home Asp.net Difference Between DataSet, DataReader, DataAdapter, DataView

Difference Between DataSet, DataReader, DataAdapter, DataView

54
4
Redirect Page on Button Click

In this tutorial, I’ll explain the difference between DataSet, DataReader, DataAdapter, DataView in .net c# as well as vb.net with examples.

Just for refreshing your memory, in my previous tutorials, I’d explained the difference between dataset and datareader, difference between dataset and datatable, difference between executereader executenonquery and executescalar, and difference between String and StringBuilder, and OOP concepts with examples along with other similar tutorials. You can definitely check out those too.

Difference Between DataSet, DataReader, DataAdapter, DataView

Following is the detailed difference between each of them:

1. DataSet

Dataset is connection-less oriented, that means whenever we bind data from the database it connects indirectly to the database and then disconnected. It has read/write access to data tables. It supports both forward and backward scanning of data.

DataSet is a container of one or more DataTable. More often than not, it will just contain one table, but if you do a query with multiple SELECT statements, the DataSet will contain a table for each.

You have to be careful about how much data you pull into a DataSet because this is an in-memory representation. You can Fill a DataSet using the Fill() method of a DataAdapter.

2. DataReader

DataReader is connection-oriented, that means whenever we bind data from the database it must require a connection and after that disconnected from the connection. It has read-only access, we can’t do any transaction on them. It supports forward-only scanning of data, in other words, you can’t go backward.

DataReader fetches one row at a time so very less network cost as compare to DataSet(that fetches all the rows at a time). It is scalable to any number of records, at least in terms of memory pressure, since it only loads one record at a time. One typical way to get a DataReader is by using the ExecuteReader() method of a DbCommand.

3. DataAdapter

DataAdapter is an ADO.NET Data Provider. DataAdapter can perform any SQL operations like Insert, Update, Delete, Select in the Data Source by using SqlCommand to transmit changes back to the database.

DataAdapter provides communication between the Dataset/DataTable and the Datasource. We can use the DataAdapter in combination with the DataSet/DataTable objects. These two objects combine to enable both data access and data manipulation capabilities.

4. DataView

Generally, we use DataView to filter and sort DataTable rows. So we can say that DataView is like a virtual subset of a DataTable. This capability allows you to have two controls bound to the same DataTable, but showing different versions of the data.

For example, one control may be bound to a DataView showing all of the rows in the table, while a second may be configured to display only the rows that have been deleted from the DataTable. The DataTable also has a DefaultView property that returns the default DataView for the table.

Download Sample Code

Git Repo

Best way to understand difference is, go through the above sample code and step through each of the statements by debugging it. That’s it!

Previous articleDifference: A Complete Guide DataSet vs DataReader in .NET
Next articleExport GridView Data to Word Excel Text Pdf File in Asp.net C# Vb
Hi there, I am Mayank, the man behind Technical Mack. I started AspnetO with a motive to educate people on various programming languages ranging from beginners to expert level. Through this blog, I aim to provide more insightful content.

4 COMMENTS

    • There is no life cycle exactly but there are set of statements that you need to follow. I recommend you to download the sample (I added separate pages for all 4 methods for beginners guide), and go through the statements. That’s it!

      I hope that will clear all of your doubts, in case if you have any doubts come back here and feel free to ask me here.

  1. Hi,

    Thanks for all of the useful articles, and i am here for requesting one more article from your side and i.e. about ASP.NET page lifecycle.
    So if you can provide the article soon then it would be very helpfull.

    Thx
    Aayush

LEAVE A REPLY

Please enter your comment!
Please enter your name here

twelve − nine =