DataReader, DataSet, DataAdapter, and DataTable are four major components of ADO.NET. In this blog, I will explain the difference between a DataReader, DataSet, DataAdapter, and DataTable with code examples in C#.
DataReader
DataReader is used to read the data from the database and it is a read and forward only connection oriented architecture during fetch the data from database. DataReader will fetch the data very fast when compared with dataset. Generally, we will use ExecuteReader object to bind data to datareader.
To bind DataReader data to GridView we need to write the code like as shown below:
protected void BindGridview() {
using(SqlConnection conn = new SqlConnection("Data Source=abc;Integrated Security=true;Initial Catalog=Test")) {
con.Open();
SqlCommand cmd = new SqlCommand("Select UserName, First Name,LastName,Location FROM Users", conn);
SqlDataReader sdr = cmd.ExecuteReader();
gvUserInfo.DataSource = sdr;
gvUserInfo.DataBind();
conn.Close();
}
}
- Holds the connection open until you are finished (don't forget to close it!).
- Can typically only be iterated over once
- Is not as useful for updating back to the database
Here is a detailed tutorial on DataReader: DataReader in ADO.NET
DataSet
DataSet is a disconnected orient architecture that means there is no need of active connections during work with datasets and it is a collection of DataTables and relations between tables. It is used to hold multiple tables with data. You can select data form tables, create views based on table and ask child rows over relations. Also DataSet provides you with rich features like saving data as XML and loading XML data.
protected void BindGridview() {
SqlConnection conn = new SqlConnection("Data Source=abc;Integrated Security=true;Initial Catalog=Test");
conn.Open();
SqlCommand cmd = new SqlCommand("Select UserName, First Name,LastName,Location FROM Users", conn);
SqlDataAdapter sda = new SqlDataAdapter(cmd);
DataSet ds = new DataSet();
sda.Fill(ds);
gvUserInfo.DataSource = ds;
gvUserInfo.DataBind();
}
DataAdapter
DataAdapter will acts as a Bridge between DataSet and database. This dataadapter object is used to read the data from database and bind that data to dataset. Dataadapter is a disconnected oriented architecture. Check below sample code to see how to use DataAdapter in code:
protected void BindGridview() {
SqlConnection con = new SqlConnection("Data Source=abc;Integrated Security=true;Initial Catalog=Test");
conn.Open();
SqlCommand cmd = new SqlCommand("Select UserName, First Name,LastName,Location FROM Users", conn);
SqlDataAdapter sda = new SqlDataAdapter(cmd);
DataSet ds = new DataSet();
sda.Fill(ds);
gvUserInfo.DataSource = ds;
gvUserInfo.DataBind();
}
- Lets you close the connection as soon it's done loading data, and may even close it for you automatically
- All of the results are available in memory
- You can iterate over it as many times as you need, or even look up a specific record by index
- Has some built-in faculties for updating back to the database.
Here is a detailed tutorial on DataAdapter: DataAdapter in C#
DataTable
DataTable represents a single table in the database. It has rows and columns. There is no much difference between dataset and datatable, dataset is simply the collection of datatables.
protected void BindGridview()
{
SqlConnection con = new SqlConnection("Data Source=abc;Integrated Security=true;Initial Catalog=Test");
conn.Open();
SqlCommand cmd = new SqlCommand("Select UserName, First Name,LastName,Location FROM Users", conn);
SqlDataAdapter sda = new SqlDataAdapter(cmd);
DataTable dt = new DataTable();
sda.Fill(dt);
gridview1.DataSource = dt;
gvidview1.DataBind();
}
Here is a detailed tutorial in DataTable: DataTable in C#

Nikos AthanasakisPosted Jul 20, 2023, 5:57 PM
Thanks you very much for your post kumar. Geat Job.
IMAD AYOUBPosted Aug 20, 2021, 10:07 PM
Excellent brief explanation. Thanks a lot
shubham gargPosted Mar 12, 2020, 4:39 AM
What is the use of sda.Fill(ds);
Kannan ThangavelPosted Oct 10, 2019, 5:27 AM
Please correct this mistake : SqlDataAdapter sda = new SqlDataAdapter(cmd); da.Fill(ds); It supposted to be sda.Fill(ds);
Vibhore JainPosted Sep 2, 2019, 12:02 PM
Thanks a lot sir
Mohammed SheikhPosted Jun 10, 2019, 9:54 AM
Very clearly explained
Hobby ProgrammerPosted Apr 5, 2019, 10:18 AM
Nicely explained, and clears my confusion. thanks for article.
bilal khattakPosted Dec 30, 2018, 11:15 PM
Hi sir...sir asp.net form aspx main abi bi job miltyy hai k nhi.......
Harender NegiPosted Dec 19, 2018, 1:11 PM
Perfect definition..... Thank you
Ankit GautamPosted Nov 20, 2018, 12:30 AM
Nice explanation..........thanks
Bhavesh JadavPosted Apr 25, 2018, 5:10 AM
Wow, very great, it is very helpful to me to clear difference between it. Thanks for sharing it.
Arslan AliPosted Apr 15, 2018, 8:28 AM
Very Clear And Core Concepts Explained , Thank You Santosh Kumar !
Javed KhanPosted Mar 26, 2018, 6:50 AM
Excellent Tutorial. Very clearly differentiation.
Dinesh AchariPosted Dec 15, 2017, 2:45 AM
Very nice.................
Mukesh KumarPosted Aug 28, 2017, 1:25 AM
You are using sda as variable for SqlDataAdapter but using da.fill(dt) it should be like sda.FIll(dt).
GuruJi PointPosted Jul 22, 2017, 3:51 AM
DataReaderDataReader works only in forward direction means row read once cannot be read again because of this it is fast to fetching records. Datareader always required a Open connection for executing the SQL commands. Once a connection closed then you will not been able to read the data from datareader. Thats why it is used in connected mode in SQL.DatAdapter DataAdapter gets all the returned rows from Sql statement at once and then fill the data into DataSet or datatable. Because of this dataadapter is slow in comparison to datareader. DataAdapter will not require any open and close connection. Means DataAdapter can work in Disconnected mode.
Saurabh patilPosted Jul 5, 2017, 4:48 AM
Simple ,clear, no doubts..... perfect answer
Patel SoniyaPosted May 31, 2017, 3:32 AM
Vry nice.................
ajit rathPosted Feb 28, 2017, 11:26 AM
Very nice.................................................
Bhuvanesh MohankumarPosted Apr 27, 2016, 1:45 PM
Clear & simple words
Vivek VijayakumarPosted Mar 12, 2016, 5:23 AM
Very Useful....
Chandu KumawatPosted Mar 10, 2016, 5:54 AM
very nice
Roshan MulePosted Feb 18, 2016, 12:19 PM
Very Useful Thank You!
Anand VigneshPosted Sep 3, 2015, 8:04 AM
Clear Explanation thanq.,
Sourav SumanPosted Jul 21, 2015, 8:24 AM
SqlDataAdapter is da or sda while making obect for further use..:)
BALA BHASKARA CHARY RAVUTLAPosted May 5, 2015, 3:26 PM
nice answers
Velsamy AnanthaveluPosted Apr 8, 2015, 1:21 AM
its very useful
Manikandan sPosted Mar 10, 2015, 6:46 AM
nyc shanthosh
sathish pPosted Dec 8, 2014, 1:46 AM
Big Thanks
Tarun SharmaPosted Oct 1, 2014, 12:54 AM
gvUserInfo.DataSource = ds; here gvUserInfo means
Mitchel RyanPosted Sep 3, 2014, 10:00 AM
Thanks. This helped me a lot
Ravikumar RamachandranPosted Mar 26, 2014, 1:54 AM
Thanks for your simple explanation.
Santosh KumarPosted Dec 26, 2013, 4:16 AM
Thanks all for response and your great comment!
Murali Krishna DoddaPosted Dec 20, 2013, 10:58 AM
Very Nice Description Sir, It's very useful to all... Thank you
MohanRaj PonnambalamPosted Nov 19, 2013, 2:59 AM
Great Work Santosh ...It's Really Understandable for Beginner's Also...
ShriPosted Oct 7, 2013, 4:26 AM
difination with good understanding.... thax bro
Santosh KumarPosted Sep 24, 2013, 3:54 AM
Thank you.
Rajan SinghPosted Jul 26, 2013, 1:26 PM
Good Description.