Click here to Skip to main content
15,886,654 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
C#
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
C#
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".
 
Share this answer
 
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.
 
Share this answer
 
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 :)
datatable = single table contain some data
dataset = bunch of multiple Datatables

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

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