Udostępnij za pośrednictwem


Data Sources Overview

Data sources represent the data available to your application, or—more specifically—they represent the data that you already know you want to work with in your application. Data sources are displayed in the Data Sources Window. You can create data sources by selecting Add New Data Source from the Data menu or from the Data Sources window. Data sources can be made from databases (including local database files), Web services, and objects.

Note

The currently supported formats of local data files are SQL Server Compact 3.5 (.sdf), Access (.mdb) and SQL Express (.mdf) files.

The data sources created by running the Data Source Configuration Wizard are available to your project as items in the Data Sources window. They can be dragged onto forms in your Windows application to create controls that display, and are bound to, the underlying data. For more information, see Displaying Data Overview.

Creating and Editing Data Sources

Visual Studio provides design-time tools for creating and editing data sources for use in your application. Data sources in Visual Studio projects are represented as datasets or other object types, depending on the objects returned from the underlying data store.

You create and edit all types of data sources with the assistance of the Data Source Configuration Wizard. In addition, data sources created as datasets can also be edited using the Dataset Designer.

Data Sources Created from Databases

You can create a data source from a database by running the Data Source Configuration Wizard and selecting the Database data source type. For more information, see How to: Connect to Data in a Database.

Creating data sources from a database adds a typed dataset to your project based on the individual database objects added to the data source. For example, creating a data source based on specific tables in a database creates a typed dataset with data tables that correspond to the tables selected. For an example of such a data source, complete the procedures in Walkthrough: Connecting to Data in a Database.

Data Sources Created from Web Services

Creating a data source from a Web service adds a project reference to the Web service and creates objects that correspond to the objects returned by the Web service. For example, a Web service that returns a dataset is represented in your project as a dataset; a Web service that returns a specific type or object is represented in your project as the type or object returned. For more information, see How to: Connect to Data in a Web Service.

Note

The items that appear in the Data Sources window are dependent on the information the Web service returns. Some Web services might not provide enough information for the Data Source Configuration Wizard to create bindable objects. For example, if the Web service returns an untyped dataset, then no items will appear in the Data Sources window upon completing the wizard. This is because untyped datasets do not provide schema, so the wizard does not have enough information to create the data source.

Data Sources Created from Objects

Data sources can be created from any object that exposes one or more public properties. No specific interfaces or default public constructors are required to create a data source from an object. All public properties are displayed in the Data Sources window and can be dragged onto a form in a Windows application to create data-bound controls. You may need to build the project that contains your object before the object appears in the wizard. To reduce the amount of unnecessary objects, all objects in a project do not automatically appear in the Data Sources window. You must add them with the Data Source Configuration Wizard if needed. For more information on binding to objects, see Object Binding in Visual Studio. For more information on creating an object data source, see Walkthrough: Creating LINQ to SQL Classes (O/R Designer).

Data Sources Created from Local Data Files

You can also create data sources from SQL Server Compact 3.5 databases (.sdf files), Access databases (.mdb files), and SQL Server Express databases (.mdf files) and add them directly to your project. A typed dataset based on the schema of the data file selected is also added to the project. For more information, see the following topics:

See Also

Concepts

What's New in Data

Displaying Data Overview

Dataset Designer

Reference

Data Sources Window

Other Resources

Getting Started with Data Access

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