Click here to Skip to main content
13,087,566 members (92,895 online)
Rate this:
Please Sign up or sign in to vote.
See more:

I wanna know about dataset and datatable.

Datatable is like a single table in database and dataset is like database that contain multiple table.

But when I write code of dataset
SqlDataAdapter da = new SqlDataAdapter("select * from tab5,tab6",con);
DataSet ds = new DataSet();
GridView1.DataSource = ds;

Dataset fetch data both of table.

coding of datatable
SqlDataAdapter da = new SqlDataAdapter("select * from tab5,tab6",con);
DataTable dt = new DataTable();
GridView1.DataSource = dt;

Datatable also fetch data both of table.

Now my question is that what is diffeence between dataset and datatable
Posted 16-Mar-13 9:03am
Rate this: bad
Please Sign up or sign in to vote.

Solution 1

A DataSet contains DataTables and their relationships (if defined in the database). Using a DataSet with a DataGridView allows the view to "drill down" to related tables.

I (and some other experienced developers) don't use DataSets, DataAdapters, and DataGridViews for "real work".
Rate this: bad
Please Sign up or sign in to vote.

Solution 2

DataTable - think as one table of database.

DataSet - think as the whole database consisting of all the tables.

=> (implies) DataSet (database) is a collection of DataTables(tables).

Note - they are disconnected architecture of the backend, where you can do any manipulation and it will not affect the database, until you update them back.

There are many other functionality and performance related differences, which you can easily get from Google.

Your example -
Now, coming to your example.
You are actually pulling data from one table not two as you have one select query.

You have mentioned two tables, but it ultimately gives result as one table by joining them.

If you will try more than one select statements pulling data from different tables, then you can see that DataTable will fail to hold the result and DataSet will succeed.
ashishadi 17-Apr-13 15:27pm
Suppose i have 2 tables say-Login and Employee and there is relation between these 2 tables in one database and i am fetching data in grid view . on the grid i have one link button for each row , when i click that link button than that related row will move from one table two another that case what will i use dataset or datatable..
Tadit Dash 18-Apr-13 0:32am
Hi @ashishadi,

Thanks for asking me the question. I have few queries and doubts as follows...

Are you showing data from both the tables.
I mean you must be joining the tables, fetching the data and then showing in GridView, right ?

And I can't understand this - "on clicking that link, row will move from one table to another"... What exactly you trying to do ? Please explain more.

ashishadi 18-Apr-13 2:08am
if i have a database, with login , employee1 and employee2 tables

and also have 2 grid views 1st grid view to fetch the data from login and employee1 ,

in 1st grid view have link button with name activate for each row n when i click that activate button the data move from employee1 to employee2 table (employee1 & employee2 have same structure) and grid view 2 used to fetch the data of employee2 that case what will i used dataset or datatable..
Tadit Dash 18-Apr-13 2:58am
Ok, so you are populating two GridViews. One from login and employee1 and another from employee2.

As you are populating two GridViews at the same time, then you can use DataSet, which will contain both the resultants.
One DataTable will contain the joining data from login and employee1 and the other DataTable will contain the data from employee2.
ashishadi 18-Apr-13 3:16am
Ok..thanx..a lot :)
Tadit Dash 18-Apr-13 3:41am
Most welcome... Anytime. :)
ashishadi 18-Apr-13 7:40am
Tadit Dash sir.. as we discuss ..i used the dataset, all is working properly ...but the problem is that , i couldn't fetch data in gridview2 from table2 (SlideShowTable2)..

can i send my demo ..can u please send me ur mail-id
thank you...
Tadit Dash 18-Apr-13 8:27am
Ok. You can send me.
But also send me the DataBase Create Scripts, as you are getting data from DataBase.
Else I will be having problem while running the app.
ashishadi 18-Apr-13 8:35am
Sir am using Access database..
Tadit Dash 18-Apr-13 11:53am
Ok. I will let u know...
Tadit Dash 19-Apr-13 9:51am
Hi @ashishadi,

I debugged your code and found that the table "SlideShowTable1" don't have any data as it is not returning anything. When I replaces it with "SlideShowTable", I am getting data and the grid is populating...

Query ->

Select u.U_id ,u.U_name, u.U_Email,s.ImageName ,s.Description,s.CategoryName,s.ADshop_name,s.ADShop_Address,s.ADshop_city,s.ADshop_mob,s.ADshop_Email,s.AreaName,s.startdate,s.enddate,s.ImagePath,s.diffrence
from LOGIN u, SlideShowTable1 s
where u.U_id=s.U_id

This is not returning any data as "SlideShowTable1" is used.

Query ->

Select u.U_id ,u.U_name, u.U_Email,s.ImageName ,s.Description,s.CategoryName,s.ADshop_name,s.ADShop_Address,s.ADshop_city,s.ADshop_mob,s.ADshop_Email,s.AreaName,s.startdate,s.enddate,s.ImagePath,s.diffrence
from LOGIN u, SlideShowTable s
where u.U_id=s.U_id

This query is returning data and GridView is populating as table "SlideShowTable" is used.

Query -> (Getting data only from "SlideShowTable1" table)

Select s.ImageName, s.Description, s.CategoryName, s.ADshop_name, s.ADShop_Address, s.ADshop_city, s.ADshop_mob, s.ADshop_Email, s.AreaName, s.startdate, s.enddate, s.ImagePath, s.diffrence from SlideShowTable1 s

This is also not returning anything.

So, basically I mean that the table "SlideShowTable1" don't have any records. And I can't open this .mdb file as I don't have Microsoft Access. So, you better check and let me know...
ashishadi 19-Apr-13 14:46pm
main ne solve kar diya hain problem...


agar kabhi problem aayto...plz help me
Tadit Dash 23-Apr-13 6:14am
Sure man... Anytime. Be in touch.
By the way what was the problem ?
ashishadi 23-Apr-13 12:55pm
i did this on update update..

double diff = 0;
if (txtdiffrence.Text != "")
diff = Convert.ToDouble(txtdiffrence.Text);
Tadit Dash 24-Apr-13 2:29am
Ok. So, you had the problem while updating, but I was looking at the data binding.
Rate this: bad
Please Sign up or sign in to vote.

Solution 3

datatable = single table contain some data
dataset = bunch of multiple Datatables

Happy Coding!
Rate this: bad
Please Sign up or sign in to vote.

Solution 5

1. Its connectionless. whenever you want fetch data from database. its connects indirectly to the database and create a virtual database in local system. then disconnected from database.
2. Its easily read and write data from virtual database.

A DataTable object represents a single table in the database. It has a name rows and columns.
There is not much difference between dataset and datatable, dataset is just the collection of datatables.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

  Print Answers RSS
Top Experts
Last 24hrsThis month

Advertise | Privacy |
Web04 | 2.8.170813.1 | Last Updated 16 May 2013
Copyright © CodeProject, 1999-2017
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100