Share via


How to: Add Columns to a DataTable

The individual columns (DataColumn) that make up data tables (DataTable) are created by adding them to the data tables DataColumnCollection. You can add columns to data tables visually with the Dataset Designer, or with one of the data wizards. To add data columns to data tables programmatically, see Adding Columns to a DataTable (ADO.NET).

Note

Your computer might show different names or locations for some of the Visual Studio user interface elements in the following instructions. The Visual Studio edition that you have and the settings that you use determine these elements. For more information, see Visual Studio Settings.

To add a column to a DataTable with the Dataset Designer

  1. Open your dataset in the Dataset Designer. For more information, see How to: Open a Dataset in the Dataset Designer.

  2. Right-click the DataTable to add the column. Point to Add, and then click Column.

  3. Replace the default column name, if desired, by selecting the column name in the data table and editing the text.

  4. Set the DataType property in the Properties window. For more information, see How to: Set the Data Type of a DataColumn.

To add a column to a DataTable with the Data Source Configuration Wizard

  1. In the Data Sources window, right-click the data source, and then click Configure DataSet with Wizard.

  2. Expand the table you want to add a column to.

  3. Select the columns to add to the table.

  4. Click Finish.

To add a column to a DataTable with the TableAdapter Configuration Wizard

  1. Open your dataset in the Dataset Designer. For more information, see How to: Open a Dataset in the Dataset Designer.

  2. Right-click the data table, and then click Configure.

  3. Add the column to the SELECT statement.

  4. Click Finish.

See Also

Tasks

Walkthrough: Displaying Data on a Windows Form

How to: Connect to Data in a Database

Concepts

TableAdapter Overview

Dataset Designer

Binding Windows Forms Controls to Data in Visual Studio

Preparing Your Application to Receive Data

Fetching Data into Your Application

Binding Controls to Data in Visual Studio

Editing Data in Your Application

Validating Data

Saving Data

Other Resources

Connecting to Data in Visual Studio