Walkthrough: Creating a DataTable in the Dataset Designer
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 How to: Create TableAdapters.
Tasks illustrated in this walkthrough include:
-
Creating a new Windows Application project
-
Adding a new dataset to the application
-
Adding a new data table to the dataset
-
Adding columns to the data table
-
Setting the primary key for the table
To create a new Windows Application project
-
From the File menu, create a new project.
-
Choose a programming language in the Project Types pane.
-
Click Windows Application in the Templates pane.
-
Name the project DataTableWalkthrough, and then click OK.
Visual Studio adds the project to Solution Explorer and displays Form1 in the designer.
To add a new dataset item to the project
-
On the Project menu, click Add New Item.
The Add New Item Dialog Box appears.
-
In the Templates box, select DataSet.
-
Click Add.
Visual Studio will add a file called DataSet1.xsd to the project and open it in the Dataset Designer.
To add a new data table 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.
Note To create a data table that includes a TableAdapter, see Walkthrough: Creating a TableAdapter with Multiple Queries.
-
Click the title bar of DataTable1 and rename it Music.
To add columns to the data table
-
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.String
Artist: System.String
Genre: System.String
Now that you have created the table, you might want to perform one of the following actions:
| To | See |
|---|---|
| Create a form to input data | Walkthrough: Displaying Data on a Form in a Windows Application. |
| Add data to the table | |
| View data in a table | |
| Edit data | |
| Delete a row from a table |