---
title: "Dataset & DataTable"  
description: "In this blog, I’m explaining the concept of dataset and datatable.  DataSetThe data set represents a subset of the database. It is the class of System"  
author: "Anchal Kesharwani"  
published: 2014-08-14  
updated: 2014-09-18  
canonical: https://www.mindstick.com/blog/684/dataset-datatable  
category: "c#"  
tags: ["c#"]  
reading_time: 2 minutes  

---

# Dataset & DataTable

In this blog, I’m explaining the concept of dataset and datatable.\

##### DataSet

The data set represents a subset of the database. It is the class of System.Data namespace. It does not have a continuous [connection](https://www.mindstick.com/articles/13012/what-makes-ethernet-connection-better-than-wifi) to the database. To [update the database](https://www.mindstick.com/forum/160254/how-to-apply-a-migration-to-update-the-database-schema-in-entity-framework-core) a reconnection is required. DataSet contains DataTableCollection and their DataRelationCollection. ADO.net dataset contains [data tables](https://www.mindstick.com/forum/1216/full-outer-join-on-2-data-tables-with-a-list-of-columns) [collections](https://www.mindstick.com/articles/12458/what-are-collections-in-c-sharp) and their [relationships](https://www.mindstick.com/blog/11850/how-to-build-stronger-relationships-with-your-employees) it represent a complete set of data including tables that contain tables rows and [constraints](https://www.mindstick.com/forum/34816/what-is-mapping-constraints-in-database-management-system).

##### Example

```
// these lines for creating connection by passing server name, database name and the trusted connection mind.            SqlConnection con = new SqlConnection();            con.ConnectionString = @"Server = MINDSTICK-2\WRIINSTANCE; Database=school; Trusted_Connection=True";            // here connection open            con.Open();            // creeate a dataadapter and invoking a command            SqlDataAdapter da = new SqlDataAdapter("SELECT *FROM Student", con);            // creating a dataset object            DataSet ds = new DataSet();            da.Fill(ds, "Student"); // use the data adapter to fill the data             // close the connection            con.Close();
```

In this example, we understand how to use of dataset.

##### DataTable

A datatable is an in-memory representation of a [single database](https://www.mindstick.com/interview/22849/at-a-same-time-can-multiple-instances-applications-access-a-single-database-file) table. Datatable is the collection of row and [as well as](https://www.mindstick.com/interview/2481/can-you-write-a-java-class-that-could-be-used-both-as-an-applet-as-well-as-an-application) table. Datatable is used to store data in memory in [SQL database](https://www.mindstick.com/articles/337535/connecting-to-sql-databases-ado-dot-net-essentials). Datatable contains a collection of constraints in database

```
// these lines for creating connection by passing server name, database name and the trusted connection mind.            SqlConnection con = new SqlConnection();            con.ConnectionString = @"Server = MINDSTICK-2\WRIINSTANCE; Database=school; Trusted_Connection=True";            // here connection open            con.Open();            // creeate a dataadapter and invoking a command            SqlDataAdapter da = new SqlDataAdapter("SELECT *FROM Student", con);            // creating a dataset object            DataSet ds = new DataSet();            da.Fill(ds, "Student"); // use the data adapter to fill the data             // create a datatable object            DataTable dt = new DataTable();            // select the table from dataset            dt = ds.Tables["Student"];            // close the connection            con.Close();
```

In this example, we understand how to use of datatable.

---

Original Source: https://www.mindstick.com/blog/684/dataset-datatable

Copyright © MindStick Software Pvt. Ltd. This Markdown version is provided for developers, AI systems, and offline reading.
