Total Page Preview:   000000020961

Difference between DataSet and DataTable in c# with example


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.


In Hindi

"Database me DataTable ek single table ko represent karta hai. esme rows and columns hote hai. DataSet and DataTable me koi jyada difference nahi hota hai, dataset sirf datatables ka collection hota hai"

Example:

//Get sql database connection
SqlConnection conn = new SqlConnection ("Data Source=127.0.0.1;Integrated ecurity=true;Initial Catalog=TestDB" );
conn.Open();
SqlCommand cmd = new SqlCommand("Select UserName, First Name,LastName,Location FROM Users" , conn);
SqlDataAdapter da = new SqlDataAdapter(cmd);
DataTable dt = new DataTable();
//Create object to DataTable
da.Fill(dt); //Fill User Data in DataTable

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.

In Hindi

"DataSet ek disconnected orient architecture hota hai, iska matlab yah hai ki datasets ke sath kaam karne ke liye koi active connections ki jarurat nahi hoti hai aur yah tables ke bich DataTables and relations ka ek collection hota hai. Yah multiple tables ke sath data ko rakhne ke liye use hota hai. Tum tables se data ko select kar sakte ho, table par based views create kar sakte ho aur relations ke upar child rows ko ask kar sakte ho. DataSet tumhe bahut sare features provide karta hai like saving data as XML and loading XML data"

Example:


//Get sql database connection
SqlConnection conn = new SqlConnection ("Data Source=127.0.0.1;Integrated ecurity=true;Initial Catalog=TestDB" );
conn.Open();
SqlCommand cmd = new SqlCommand("Select UserName, First Name,LastName,Location FROM Users" , conn);
SqlDataAdapter da = new SqlDataAdapter(cmd);
DataTable dt = new DataTable();
//Create object to DataTable
da.Fill(dt); //Fill User Data in DataTable

Difference between DataSet and DataTable in c#

  DataSet DataTable
1

A DataSet is an in-memory representation of a database-like structure which has collection of DataTables.


In Hindi

"Ek dataset ek database-like structure ka ek in-memory representation hai jisme datatables ka collection hota hai"

A DataTable is an in-memory representation of a single database table which has collection of rows and columns


In Hindi

"Ek datatable ek single database table ka ek in-memory representation hai jisme rows and columns ka collection hota hai"

2

It has a collection of datatables.


In Hindi

"Yah datatables ka collection hota hai"

It has a collection of rows and columns.


In Hindi

"Yah rows and columns ka collection hota hai"

3

Enforcing Data Integrity: In DataSet, data integrity is enforced by using the UniqueConstraint and ForeignKeyConstraint objects.


In Hindi

"DataSet me, data integrity UniqueConstraint and ForeignKeyConstraint objects ke using ke dwara enforced hoti hai"

Enforcing Data Integrity: In DataTable, there is no UniqueConstraint and ForeignKeyConstraint objects available.


In Hindi

"DataTable me, koi bhi UniqueConstraint and ForeignKeyConstraint objects available nahi hota hai"

4

Number of rows retrieved at a time: DataSet can fetch multiple TableRows at a time


In Hindi

"DataSet ek baar me multiple TableRows ko fetch kar sakta hai"

Number of rows retrieved at a time: DataTable fetches only one TableRow at a time


In Hindi

"DataTable ek baar me sirf ek hi TableRow ko fetch karta hai"

5

DataSource can be Serialized or Not:
DataSet is serialized DataSource .That is why web services can always returns DataSet as the result but not the DataTables.


In Hindi

"DataSet serialized DataSource hai. Isliye web services as the result hamesa DataSet return karti hai DataTables nahi karti hai"

DataSource can be Serialized or Not:
In DataTable, DataSource cannot be serialized.


In Hindi

"DataTable me, DataSource serialized nahi hota hai"

Difference Between Dataset And DataTable In CSharp
 


DataSet and DataTable

Difference between DataSet and DataTable in c#
 
 

 

 

Thank You

About Author

Brijesh Kumar

Database Developer

I have more then 6 years Experience in Microsoft Technologies - SQL Server Database, ETL Azure Cloud - Azure SQL Database, CosmosDB, Azure Data Factory, PowerBI, Web Job, Azure Function, Azure Storage, Web Apps, Powershall and Database Migration On-Premise to Azure Cloud.
LinkedIn : https://www.linkedin.com



Comments

Brijesh Kumar
07-Sep-2016
very nice article and useful us.
Thomas
01-Dec-2019
Wⲟuld anyⲟne recommend Peaches and Screams UK (https://peachesandscreams.co.uk) fߋr saucy Christmas gifts? Ӏ гeally love tһeir Midnight Fantasy Lace Chemise Тhanks in advance :D
Haddon
06-Dec-2019
Good Morning everybody аt ithubcity.ⅽom, we are presently taking on neѡ reviewers who wοuld bе interested iin reviewing our CBD products ѕuch as CBD GUMMIES. If іnterested, please feel free to reach οut to me on https://www.justcbdstore.com
espn.com/activate
10-Dec-2019
Ask any Search Engine Optimiser, writing a blog post, no matter how good it is, won't bring you any links. Sitting tight after finishing an awesome content is the last thing that you should do, if you want to get high traffic and social shares to the blog post.
Duigan
15-Jan-2020
Excellent beat ! I wish to apprentice whilst you amend your site, how could i subscribe for a blog web site? The account helped me a acceptable deal. I have been a little bit acquainted of this your broadcast offered bright clear idea
Riddoch
03-Jul-2020
I am no longer sure the place you're getting your info, however good topic. I needs to spend a while learning more or working out more. Thanks for magnificent information I was in search of this info for my mission.
Mullin
08-Jul-2020
I have to thank you for the efforts you've put in writing this site. I really hope to see the same high-grade content by you in the future as well. In fact, your creative writing abilities has motivated me to get my own website now ;)

                           
                           

                           

                           

Facebook User: