Click here to Skip to main content
14,695,439 members
Please Sign up or sign in to vote.
2.60/5 (2 votes)
See more:
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
v2

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".
   
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
Raj@88 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..
   
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
Raj@88 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..
   
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.
Raj@88 18-Apr-13 3:16am
   
Ok..thanx..a lot :)
   
Most welcome... Anytime. :)
Raj@88 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...
   
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.
Raj@88 18-Apr-13 8:35am
   
Sir am using Access database..
   
Ok. I will let u know...
   
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...
Raj@88 19-Apr-13 14:46pm
   
main ne solve kar diya hain problem...

anyways...thanx..

agar kabhi problem aayto...plz help me
   
Sure man... Anytime. Be in touch.
By the way what was the problem ?
Raj@88 23-Apr-13 12:55pm
   
i did this on update update..

double diff = 0;
if (txtdiffrence.Text != "")
{
diff = Convert.ToDouble(txtdiffrence.Text);
}
   
Ok. So, you had the problem while updating, but I was looking at the data binding.
datatable = single table contain some data
dataset = bunch of multiple Datatables

Happy Coding!
:)
   
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.
   

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




CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900