Walkthrough: Create a DataTable for .NET Framework applications using the Dataset Designer
Note
Datasets and related classes are legacy .NET Framework technologies from the early 2000s that enable applications to work with data in memory while the applications are disconnected from the database. They are especially useful for applications that enable users to modify data and persist the changes back to the database. Although datasets have proven to be a very successful technology, we recommend that new .NET applications use Entity Framework Core. Entity Framework provides a more natural way to work with tabular data as object models, and it has a simpler programming interface.
This walkthrough explains how to create a DataTable (without a TableAdapter) using the Dataset Designer. For information on creating data tables that include TableAdapters, see Create and configure TableAdapters.
Prerequisites
To complete this tutorial, you need the .NET desktop development and Data storage and processing workloads installed in Visual Studio. To install them, open Visual Studio Installer and choose Modify (or More > Modify) next to the version of Visual Studio you want to modify. See Modify Visual Studio.
Create a new Windows Forms application
In Visual Studio, create a new Windows Forms App (.NET Framework) project and name it DataTableWalkthrough.
The DataTableWalkthrough project is created and added to Solution Explorer.
Add a new Dataset to the application
On the Project menu, select Add New Item.
The Add New Item dialog box appears.
In the left-hand pane, select Data, then select DataSet in the middle pane.
Choose Add.
Visual Studio adds a file called DataSet1.xsd to the project and opens it in the Dataset Designer.
Add a new DataTable to the Dataset
Drag a DataTable from the DataSet tab of the Toolbox onto the Dataset Designer.
A table named DataTable1 is added to the dataset.
Click the title bar of DataTable1 and rename it
Music
.
Add columns to the DataTable
Right-click the Music table. Point to Add, and then click Column.
Name the column
SongID
.In the Properties window, set the DataType property to System.Int16.
Repeat this process and add the following columns:
SongTitle
: System.StringArtist
: System.StringGenre
: System.String
Set the Primary Key for the table
All data tables should have a primary key. A primary key uniquely identifies a specific record in a data table.
To set the primary key, right-click the SongID column, and then click Set Primary Key. A key icon appears next to the SongID column.
Save Your Project
To save the DataTableWalkthrough project, on the File menu, select Save All.
Related content
Feedback
https://aka.ms/ContentUserFeedback.
Coming soon: Throughout 2024 we will be phasing out GitHub Issues as the feedback mechanism for content and replacing it with a new feedback system. For more information see:Submit and view feedback for