You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: docs/data-tools/add-new-data-sources.md
+21-15Lines changed: 21 additions & 15 deletions
Original file line number
Diff line number
Diff line change
@@ -16,7 +16,7 @@ ms.subservice: data-tools
16
16
#customer intent: As a developer, I want to add .NET Framework data sources with ADO.NET in Visual Studio, so I can connect data stores to my application.
17
17
---
18
18
19
-
# Add data sources in ADO.NET applications for .NET Framework
19
+
# Add data sources in ADO.NET applications (.NET Framework)
20
20
21
21
When you work with .NET data tools in Visual Studio, you can add *data sources* (.NET objects) to connect your .NET application to information in data stores. The Visual Studio designers can consume the data source output to generate boilerplate code that binds the data to forms when you drag and drop database objects from the **Data Sources** window.
22
22
@@ -36,7 +36,7 @@ Examples of data sources include:
36
36
37
37
## Prerequisites
38
38
39
-
- An application that implements Windows Forms or Windows Presentation Format (WPF) objects that target the .NET Framework. You can create this type of application by using a template in Visual Studio when your installation includes the **.NET Desktop development** workload. For more information, see [Modify Visual Studio workloads, components, and language packs](../install/modify-visual-studio).
39
+
- An application that implements Windows Forms or Windows Presentation Format (WPF) objects that target .NET Framework. You can create this type of application by using a template in Visual Studio when your installation includes the **.NET Desktop development** workload. For more information, see [Modify Visual Studio workloads, components, and language packs](../install/modify-visual-studio.md).
40
40
41
41
> [!IMPORTANT]
42
42
> The features described in this article aren't supported for **.NET Core** development for WPF or Windows Forms.
@@ -46,6 +46,8 @@ Examples of data sources include:
46
46
> [!TIP]
47
47
> When the application doesn't use one or more of these components, the concept of a "data source" doesn't apply. In these scenarios, you can connect directly to the database by using [SqlCommand class](/dotnet/api/system.data.sqlclient.sqlcommand?view=netframework-4.8.1&preserve-view=true) objects.
48
48
49
+
<aname="data-sources-window"></a>
50
+
49
51
## Work with data sources and Windows forms
50
52
51
53
You create and edit data sources for .NET Framework by using the **Data Source Configuration Wizard** in a Windows Forms or WPF application. You can create a data source from a database, a service, an object, or from a SharePoint list:
@@ -54,7 +56,7 @@ You create and edit data sources for .NET Framework by using the **Data Source C
54
56
55
57
After you create data sources, they're visible in the **Data Sources** window. When your project is open in Visual Studio, you can access this window by selecting **View** > **Other Windows** > **Data Sources**. You can also use the **Shift**+**Alt**+**D** keyboard shortcut.
56
58
57
-
In a Windows Forms project that targets the **.NET Framework** (not .NET Core or .NET 5 or later), you can drag a data source from the **Data Sources** window onto a Windows form design surface or control. Some examples of how you can connect a data source with a form include:
59
+
In a Windows Forms project that targets **.NET Framework** (not .NET Core or .NET 5 or later), you can drag a data source from the **Data Sources** window onto a Windows form design surface or control. Some examples of how you can connect a data source with a form include:
58
60
59
61
- Drag a table to get a [BindingNavigator](/dotnet/desktop/winforms/controls/bindingnavigator-control-overview-windows-forms) and a [DataGridView](/dotnet/desktop/winforms/controls/datagridview-control-windows-forms) for the table.
60
62
@@ -77,9 +79,7 @@ These actions trigger Visual Studio to generate boilerplate code that displays t
77
79
78
80
## Create data source from database or database file
79
81
80
-
You can create a dataset or an Entity Framework model to use as a data source for a database or database file with the **Data Source Configuration Wizard**. If your configuration uses Entity Framework, first create your [Entity classes](#create-entity-framework-classes), and then use the wizard to create data sources.
81
-
82
-
For detailed instructions to complete the wizard, see [Create and configure datasets in the .NET Framework with Visual Studio](create-and-configure-datasets-in-visual-studio.md).
82
+
You can create a dataset or an Entity Framework model to use as a data source for a database or database file with the **Data Source Configuration Wizard**. If your configuration uses Entity Framework, first create your [Entity classes](#create-entity-framework-model-as-data-source), and then use the wizard to create data sources.
83
83
84
84
### Create dataset as data source
85
85
@@ -97,6 +97,8 @@ Follow these steps to create a dataset as a data source:
97
97
98
98
1. Select the database objects to include in the dataset, and complete the wizard.
99
99
100
+
For detailed instructions to complete the wizard, see [Create and configure datasets in .NET Framework with Visual Studio](create-and-configure-datasets-in-visual-studio.md).
101
+
100
102
### Create Entity Framework model as data source
101
103
102
104
When your configuration uses Entity Framework, you first create your Entity classes and then use the **Data Source Configuration Wizard** to create the data source.
@@ -129,9 +131,13 @@ Follow these steps to create an Entity Framework model as a data source with the
129
131
130
132
For detailed instructions to complete the wizard, see [Create Model Classes with the Entity Framework (C#)](/aspnet/mvc/overview/older-versions-1/models-data/creating-model-classes-with-the-entity-framework-cs).
131
133
132
-
The generated classes for the model are now available in the **Data Source Configuration Wizard** when you choose the **Objects** category. You can select the tables (or individual columns), stored procedures, functions, and views from the model to use in the dataset.
134
+
1. After you generate classes for the model, you can create a data source from an object with the **Data Source Configuration Wizard**.
133
135
134
-
:::image type="content" source="./media/raddata-data-source-configuration-wizard-with-entity-classes.png" alt-text="Screenshot that shows the generated Entity classes for the model in the Data Source Configuration Wizard.":::
136
+
- Select the tables (or individual columns), stored procedures, functions, and views from the model for use in the dataset.
137
+
138
+
:::image type="content" source="./media/raddata-data-source-configuration-wizard-with-entity-classes.png" alt-text="Screenshot that shows the generated Entity classes for the model in the Data Source Configuration Wizard.":::
139
+
140
+
For detailed instructions, see [Create data source from object](#create-data-source-from-object).
135
141
136
142
## Create data source from service
137
143
@@ -156,14 +162,17 @@ Follow these steps to create a data source from a service:
156
162
157
163
The **Add Service Reference** dialog opens. You can also access this dialog by right-clicking your project in **Solution Explorer** and selecting **Add service reference**.
158
164
159
-
For detailed instructions to complete the wizard, see [Create and configure datasets in the .NET Framework with Visual Studio](create-and-configure-datasets-in-visual-studio.md).
165
+
For detailed instructions to complete the wizard, see [Create and configure datasets in .NET Framework with Visual Studio](create-and-configure-datasets-in-visual-studio.md).
160
166
161
167
## Create data source from object
162
168
163
169
The **Data Source Configuration Wizard** also lets you create a data source from any object that exposes one or more public properties.
164
170
165
171
All public properties of an object are visible in the **Data Sources** window. If you're using Entity Framework with a generated model, this window shows the entity classes that are the data sources for your application.
166
172
173
+
> [!NOTE]
174
+
> To support drag-and-drop data binding, objects that implement the <xref:System.ComponentModel.ITypedList> or <xref:System.ComponentModel.IListSource> interface must have a default constructor. Otherwise, Visual Studio can't instantiate the data-source object and shows an error when you drag the item to the design surface.
175
+
167
176
Follow these steps to create a data source from an object:
168
177
169
178
1. In Visual Studio, select **Project** > **Add New Data Source** to open the **Data Source Configuration Wizard**.
@@ -181,10 +190,7 @@ Follow these steps to create a data source from an object:
181
190
> [!NOTE]
182
191
> You might need to build the project that contains your objects before the objects appear in the tree view.
183
192
184
-
For detailed instructions to complete the wizard, see [Create and configure datasets in the .NET Framework with Visual Studio](create-and-configure-datasets-in-visual-studio.md).
185
-
186
-
> [!NOTE]
187
-
> To support drag-and-drop data binding, objects that implement the <xref:System.ComponentModel.ITypedList> or <xref:System.ComponentModel.IListSource> interface must have a default constructor. Otherwise, Visual Studio can't instantiate the data-source object and shows an error when you drag the item to the design surface.
193
+
For detailed instructions to complete the wizard, see [Create and configure datasets in .NET Framework with Visual Studio](create-and-configure-datasets-in-visual-studio.md).
188
194
189
195
## Create data source from SharePoint list
190
196
@@ -201,9 +207,9 @@ Follow these steps to create a data source from a SharePoint list:
201
207
202
208
1. Use the **Add Service Reference** dialog to connect to the SharePoint data service by pointing to the SharePoint Server.
203
209
204
-
For detailed instructions to complete the wizard, see [Create and configure datasets in the .NET Framework with Visual Studio](create-and-configure-datasets-in-visual-studio.md).
210
+
For detailed instructions to complete the wizard, see [Create and configure datasets in .NET Framework with Visual Studio](create-and-configure-datasets-in-visual-studio.md).
205
211
206
212
## Related content
207
213
208
214
- Explore [Visual Studio data tools for .NET](visual-studio-data-tools-for-dotnet.md)
209
-
-[Create and configure datasets in the .NET Framework with Visual Studio](create-and-configure-datasets-in-visual-studio.md)
215
+
-[Create and configure datasets in .NET Framework with Visual Studio](create-and-configure-datasets-in-visual-studio.md)
0 commit comments