Share via


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

Creating a New Windows Application

To create a new Windows Application project

  1. From the File menu, create a new project.

  2. Choose a programming language in the Project Types pane.

  3. Click Windows Application in the Templates pane.

  4. Name the project DataTableWalkthrough, and then click OK.

    Visual Studio adds the project to Solution Explorer and displays Form1 in the designer.

Adding a New Dataset to the Application

To add a new dataset item to the project

  1. On the Project menu, click Add New Item.

    The Add New Item Dialog Box appears.

  2. In the Templates box, select DataSet.

  3. Click Add.

    Visual Studio will add a file called DataSet1.xsd to the project and open it in the Dataset Designer.

Adding a New DataTable to the Dataset

To add a new data table to the dataset

  1. 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.

  2. Click the title bar of DataTable1 and rename it Music.

Adding Columns to the Data Table

To add columns to the data table

  1. Right-click the Music table. Point to Add, and then click Column.

  2. Name the column SongID.

  3. In the Properties window, set the DataType property to System.Int16.

  4. Repeat this process and add the following columns:

    SongTitle: System.String

    Artist: System.String

    Genre: System.String

Setting 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 of the data table

  • Right-click the SongID column, and then click Set Primary Key.

    A key icon appears next to the SongID column.

Saving Your Project

To save the DataTableWalkthrough project

  • On the File menu, click Save All.

Next Steps

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

Adding Data to a DataTable (ADO.NET).

View data in a table

Viewing Data in a DataTable (ADO.NET).

Edit data

Editing Data in a DataTable (ADO.NET)

Delete a row from a table

Deleting DataRows (ADO.NET)

See Also

Other Resources

Connecting to Data in Visual Studio

Preparing Your Application to Receive Data

Fetching Data into Your Application

Displaying Data on Forms in Windows Applications

Editing Data in Your Application

Validating Data

Saving Data

Data Walkthroughs