共用方式為


Binding Controls to Data in Visual Studio

You can display data to users of your application by binding data to controls. You can create these data-bound controls by dragging items from the Data Sources window onto a design surface in Visual Studio.

This topic describes the data sources you can use to create data-bound controls. It also describes some of the general tasks involved in data binding. For more specific details about how to create data-bound controls, see Binding Windows Forms Controls to Data in Visual Studio, Binding WPF Controls to Data in Visual Studio and Binding Silverlight Controls to Data in Visual Studio.

Data Sources

A data source represents the data that is available to your application. You can create data sources from databases, services, or objects. For more information, see Data Sources Overview.

Some data sources enable you to create data-bound controls by dragging items from the Data Sources window, while other data sources do not. The following table shows which data sources are supported.

Data source

Drag-and-drop support in the Windows Forms Designer

Drag-and-drop support in the WPF Designer

Drag-and-drop support in the Silverlight Designer

Dataset

Yes

Yes

No

Entity Data Model

No1

Yes

Yes

LINQ to SQL classes

No2

No2

No2

Services (including WCF Data Services, WCF services, and Web services)

Yes

Yes

Yes

Object

Yes

Yes

Yes

SharePoint

Yes

Yes

Yes

1. When the Windows Forms Designer is open, entities in the Data Sources window are read-only and cannot be dragged to the designer. However, you can still create data-bound controls by adding a new object data source that is based on the Entity Data Model, and then dragging those objects to the designer.

2. LINQ to SQL classes do not appear in the Data Sources window. However, you can add a new object data source that is based on LINQ to SQL classes, and then drag those objects to the designer to create data-bound controls. For more information, see Walkthrough: Creating LINQ to SQL Classes (O/R Designer).

Data Sources Window

Data sources are available to your project as items in the Data Sources window. You can drag items from this window to create controls that are bound to the underlying data. For more information, see Data Sources Window.

For each data type that appears in the Data Sources window, a default control is created when you drag the item to the designer. Before you drag an item from the Data Sources window, you can change the control that will be created. For more information, see How to: Set the Control to be Created when Dragging from the Data Sources Window.

Tasks Involved in Binding Controls to Data

The following table lists some of the most common tasks you follow to bind controls to data.

Task

More information

Open the Data Sources window

How to: Open the Data Sources Window

Add a data source to your project

How to: Connect to Data in a Database

How to: Connect to Data in Objects

How to: Connect to Data in a Service

Set the control that is created when you drag an item from the Data Sources window to the designer.

How to: Set the Control to be Created when Dragging from the Data Sources Window

Modify the list of controls that are associated with items in the Data Sources window.

How to: Add Custom Controls to the Data Sources Window

Create data-bound controls.

Binding Windows Forms Controls to Data in Visual Studio

Binding WPF Controls to Data in Visual Studio

Binding Silverlight Controls to Data in Visual Studio

After you create controls that are bound to data, you might want to do one of the following tasks.

Task

For More Information

Edit the data in the underlying data source

Editing Data in Your Application

Validate changes that were made to the data

Validating Data

Save updated data back to the database

Saving Data

See Also

Tasks

How to: Bind Controls to Pictures from a Database

Concepts

Binding Windows Forms Controls to Data in Visual Studio

Binding WPF Controls to Data in Visual Studio

Editing Data in Your Application

Validating Data

Saving Data

Other Resources

Binding Silverlight Controls to Data in Visual Studio

Overview of Data Applications in Visual Studio

Connecting to Data in Visual Studio

Tools for Working with Data Sources in Visual Studio