C# Programming > Data

C# Strong-Typed Dataset

C# DataSet

A C# DataSet object is a powerful class that keeps track of data. DataSets are commonly used for building database applications with SQL or XML for smaller scales.

A C# DataSet contains a list of tables, each of which contain rows of data that matches their column template. For example, a C# application can have a car DataSet, a sportcars Table, and then entries of different models of cars.

The raw data can then be saved and loaded to an SQL database. However, if your C#.Net application does not use SQL, DataSets can easily be saved to an XML file instead and loaded later on. As you see a C# DataSet is remarkably flexible.

Strong-Typed vs Weaked-Typed

A C# strong-typed Dataset, as opposed to a weak-typed one, is created during design-time by the programmer. Tables and columns for those tables are established ahead of time. Usually this is done to make it easier to program C# applications that use the particular Dataset and to establish a very specific template of how the data will be handled.

How to Create a Strong-Typed Dataset

Once you have a C# project established, go to the Project menu, and click on Add New Item.... In the dialog that appears, find the DataSet option. For users of the full version of Visual Studio, it is located under the Data category.

Name the dataset something meaningful and click Add. This will bring up the DataSet designer. User the right-click menu to start adding Tables and Columns to those tables. Just make sure to name objects properly and set the data-type of columns.

Adding C# DataSet to the Project

Once you have designed the DataSet to your liking, hit F6 to build the solution. This triggers Visual Studio to compile the DataSet and add it to the top of the Toolbox Panel. Either double-click on it or click-and-drag it into a Windows Form to create a strong-typed dataset object.

Alternatively, you can programmatically create the same strong-type C# DataSet by using the name that you gave the DataSet...


Back to C# Article List