Click here to Skip to main content
Rate this: bad
good
Please Sign up or sign in to vote.
See more: ASP.NET
Hi........
 
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();
da.Fill(ds);
GridView1.DataSource = ds;
GridView1.DataBind();
 

Dataset fetch data both of table.
 
coding of datatable
SqlDataAdapter da = new SqlDataAdapter("select * from tab5,tab6",con);
 
DataTable dt = new DataTable();
da.Fill(dt);
 
GridView1.DataSource = dt;
GridView1.DataBind();
 

Datatable also fetch data both of table.
 
Now my question is that what is diffeence between dataset and datatable
Posted 16-Mar-13 10:03am
v2
Rate this: bad
good
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".
  Permalink  
Rate this: bad
good
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.
Comments
ashishadi at 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 table...in that case what will i use dataset or datatable..
Tadit Dash at 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.
 
Thanks,
Tadit
ashishadi at 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 ..in that case what will i used dataset or datatable..
Tadit Dash at 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 at 18-Apr-13 3:16am
   
Ok..thanx..a lot :)
Tadit Dash at 18-Apr-13 3:41am
   
Most welcome... Anytime. :)
ashishadi at 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 at 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 at 18-Apr-13 8:35am
   
Sir am using Access database..
Tadit Dash at 18-Apr-13 11:53am
   
Ok. I will let u know...
Tadit Dash at 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...
 
Case-1
------
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.
 
Case-2
------
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.
 
Case-3
------
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 at 19-Apr-13 14:46pm
   
main ne solve kar diya hain problem...
 
anyways...thanx..
 
agar kabhi problem aayto...plz help me
Tadit Dash at 23-Apr-13 6:14am
   
Sure man... Anytime. Be in touch.
By the way what was the problem ?
ashishadi at 23-Apr-13 12:55pm
   
i did this on update update..
 
double diff = 0;
if (txtdiffrence.Text != "")
{
diff = Convert.ToDouble(txtdiffrence.Text);
}
Tadit Dash at 24-Apr-13 2:29am
   
Ok. So, you had the problem while updating, but I was looking at the data binding.
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 3

datatable = single table contain some data
dataset = bunch of multiple Datatables
 
Happy Coding!
Smile | :)
  Permalink  
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 5

DataSet
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.
 
DataTable
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.
  Permalink  

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

  Print Answers RSS
0 Marcin Kozub 265
1 Richard MacCutchan 239
2 OriginalGriff 208
3 Sergey Alexandrovich Kryukov 185
4 Praneet Nadkar 167
0 OriginalGriff 7,913
1 Sergey Alexandrovich Kryukov 7,232
2 DamithSL 5,604
3 Manas Bhardwaj 4,986
4 Maciej Los 4,865


Advertise | Privacy | Mobile
Web03 | 2.8.1411023.1 | Last Updated 16 May 2013
Copyright © CodeProject, 1999-2014
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