Total Page Preview:   000000047450

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


                           
                           

                           

                           

Facebook User: