Skip to content

Commit 6f7210a

Browse files
authored
update sample db instructions (#44435)
1 parent 18d5200 commit 6f7210a

8 files changed

+340
-340
lines changed

docs/visual-basic/programming-guide/language-features/linq/how-to-call-a-stored-procedure-by-using-linq.md

Lines changed: 54 additions & 54 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
description: "Learn more about: How to: Call a Stored Procedure by Using LINQ (Visual Basic)"
33
title: "How to: Call a Stored Procedure by Using LINQ"
44
ms.date: 07/20/2015
5-
helpviewer_keywords:
5+
helpviewer_keywords:
66
- "queries [LINQ in Visual Basic], stored procedure calls"
77
- "stored procedures sample [Visual Basic]"
88
- "stored procedures [LINQ to SQL]"
@@ -11,59 +11,59 @@ ms.assetid: 6436d384-d1e0-40aa-8afd-451007477260
1111
---
1212
# How to: Call a Stored Procedure by Using LINQ (Visual Basic)
1313

14-
Language-Integrated Query (LINQ) makes it easy to access database information, including database objects such as stored procedures.
15-
16-
The following example shows how to create an application that calls a stored procedure in a SQL Server database. The sample shows how to call two different stored procedures in the database. Each procedure returns the results of a query. One procedure takes input parameters, and the other procedure does not take parameters.
17-
18-
The examples in this topic use the Northwind sample database. If you do not have this database on your development computer, you can download it from the Microsoft Download Center. For instructions, see [Downloading Sample Databases](../../../../framework/data/adonet/sql/linq/downloading-sample-databases.md).
19-
20-
[!INCLUDE[note_settings_general](~/includes/note-settings-general-md.md)]
21-
22-
### To create a connection to a database
23-
24-
1. In Visual Studio, open **Server Explorer**/**Database Explorer** by clicking **Server Explorer**/**Database Explorer** on the **View** menu.
25-
26-
2. Right-click **Data Connections** in **Server Explorer**/**Database Explorer** and then click **Add Connection**.
27-
28-
3. Specify a valid connection to the Northwind sample database.
29-
30-
### To add a project that contains a LINQ to SQL file
31-
32-
1. In Visual Studio, on the **File** menu, point to **New** and then click **Project**. Select Visual Basic **Windows Forms Application** as the project type.
33-
34-
2. On the **Project** menu, click **Add New Item**. Select the **LINQ to SQL Classes** item template.
35-
36-
3. Name the file `northwind.dbml`. Click **Add**. The Object Relational Designer (O/R Designer) is opened for the northwind.dbml file.
37-
38-
### To add stored procedures to the O/R Designer
39-
40-
1. In **Server Explorer**/**Database Explorer**, expand the connection to the Northwind database. Expand the **Stored Procedures** folder.
41-
42-
If you have closed the O/R Designer, you can reopen it by double-clicking the northwind.dbml file that you added earlier.
43-
44-
2. Click the **Sales by Year** stored procedure and drag it to the right pane of the designer. Click the **Ten Most Expensive Products** stored procedure drag it to the right pane of the designer.
45-
46-
3. Save your changes and close the designer.
47-
48-
4. Save your project.
49-
50-
### To add code to display the results of the stored procedures
51-
52-
1. From the **Toolbox**, drag a <xref:System.Windows.Forms.DataGridView> control onto the default Windows Form for your project, Form1.
53-
54-
2. Double-click Form1 to add code to its `Load` event.
55-
56-
3. When you added stored procedures to the O/R Designer, the designer added a <xref:System.Data.Linq.DataContext> object for your project. This object contains the code that you must have to access those procedures. The <xref:System.Data.Linq.DataContext> object for the project is named based on the name of the .dbml file. For this project, the <xref:System.Data.Linq.DataContext> object is named `northwindDataContext`.
57-
58-
You can create an instance of the <xref:System.Data.Linq.DataContext> in your code and call the stored procedure methods specified by the O/R Designer. To bind to the <xref:System.Windows.Forms.DataGridView> object, you may have to force the query to execute immediately by calling the <xref:System.Linq.Enumerable.ToList%2A> method on the results of the stored procedure.
59-
60-
Add the following code to the `Load` event to call either of the stored procedures exposed as methods for your data context.
61-
62-
[!code-vb[VbLINQtoSQLHowTos#1](~/samples/snippets/visualbasic/VS_Snippets_VBCSharp/VbLINQtoSQLHowTos/VB/Form3.vb#1)]
63-
[!code-vb[VbLINQtoSQLHowTos#2](~/samples/snippets/visualbasic/VS_Snippets_VBCSharp/VbLINQtoSQLHowTos/VB/Form3.vb#2)]
64-
65-
4. Press F5 to run your project and view the results.
66-
14+
Language-Integrated Query (LINQ) makes it easy to access database information, including database objects such as stored procedures.
15+
16+
The following example shows how to create an application that calls a stored procedure in a SQL Server database. The sample shows how to call two different stored procedures in the database. Each procedure returns the results of a query. One procedure takes input parameters, and the other procedure does not take parameters.
17+
18+
The examples in this article use the Northwind sample database. To obtain the database, see [Downloading Sample Databases](../../../../framework/data/adonet/sql/linq/downloading-sample-databases.md).
19+
20+
[!INCLUDE[note_settings_general](~/includes/note-settings-general-md.md)]
21+
22+
## To create a connection to a database
23+
24+
1. In Visual Studio, open **Server Explorer**/**Database Explorer** by clicking **Server Explorer**/**Database Explorer** on the **View** menu.
25+
26+
2. Right-click **Data Connections** in **Server Explorer**/**Database Explorer** and then click **Add Connection**.
27+
28+
3. Specify a valid connection to the Northwind sample database.
29+
30+
## To add a project that contains a LINQ to SQL file
31+
32+
1. In Visual Studio, on the **File** menu, point to **New** and then click **Project**. Select Visual Basic **Windows Forms Application** as the project type.
33+
34+
2. On the **Project** menu, click **Add New Item**. Select the **LINQ to SQL Classes** item template.
35+
36+
3. Name the file `northwind.dbml`. Click **Add**. The Object Relational Designer (O/R Designer) is opened for the northwind.dbml file.
37+
38+
## To add stored procedures to the O/R Designer
39+
40+
1. In **Server Explorer**/**Database Explorer**, expand the connection to the Northwind database. Expand the **Stored Procedures** folder.
41+
42+
If you have closed the O/R Designer, you can reopen it by double-clicking the northwind.dbml file that you added earlier.
43+
44+
2. Click the **Sales by Year** stored procedure and drag it to the right pane of the designer. Click the **Ten Most Expensive Products** stored procedure drag it to the right pane of the designer.
45+
46+
3. Save your changes and close the designer.
47+
48+
4. Save your project.
49+
50+
## To add code to display the results of the stored procedures
51+
52+
1. From the **Toolbox**, drag a <xref:System.Windows.Forms.DataGridView> control onto the default Windows Form for your project, Form1.
53+
54+
2. Double-click Form1 to add code to its `Load` event.
55+
56+
3. When you added stored procedures to the O/R Designer, the designer added a <xref:System.Data.Linq.DataContext> object for your project. This object contains the code that you must have to access those procedures. The <xref:System.Data.Linq.DataContext> object for the project is named based on the name of the .dbml file. For this project, the <xref:System.Data.Linq.DataContext> object is named `northwindDataContext`.
57+
58+
You can create an instance of the <xref:System.Data.Linq.DataContext> in your code and call the stored procedure methods specified by the O/R Designer. To bind to the <xref:System.Windows.Forms.DataGridView> object, you may have to force the query to execute immediately by calling the <xref:System.Linq.Enumerable.ToList%2A> method on the results of the stored procedure.
59+
60+
Add the following code to the `Load` event to call either of the stored procedures exposed as methods for your data context.
61+
62+
[!code-vb[VbLINQtoSQLHowTos#1](~/samples/snippets/visualbasic/VS_Snippets_VBCSharp/VbLINQtoSQLHowTos/VB/Form3.vb#1)]
63+
[!code-vb[VbLINQtoSQLHowTos#2](~/samples/snippets/visualbasic/VS_Snippets_VBCSharp/VbLINQtoSQLHowTos/VB/Form3.vb#2)]
64+
65+
4. Press <kbd>F5</kbd> to run your project and view the results.
66+
6767
## See also
6868

6969
- [LINQ](index.md)

docs/visual-basic/programming-guide/language-features/linq/how-to-count-sum-or-average-data-by-using-linq.md

Lines changed: 55 additions & 55 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
description: "Learn more about: How to: Count, Sum, or Average Data by Using LINQ (Visual Basic)"
33
title: "How to: Count, Sum, or Average Data by Using LINQ"
44
ms.date: 07/20/2015
5-
helpviewer_keywords:
5+
helpviewer_keywords:
66
- "average operator [LINQ in Visual Basic]"
77
- "aggregate operator [LINQ in Visual Basic]"
88
- "aggregate queries"
@@ -19,60 +19,60 @@ ms.assetid: 51ca1f59-7770-4884-8b76-113002e54fc0
1919
---
2020
# How to: Count, Sum, or Average Data by Using LINQ (Visual Basic)
2121

22-
Language-Integrated Query (LINQ) makes it easy to access database information and execute queries.
23-
24-
The following example shows how to create a new application that performs queries against a SQL Server database. The sample counts, sums, and averages the results by using the `Aggregate` and `Group By` clauses. For more information, see [Aggregate Clause](../../../language-reference/queries/aggregate-clause.md) and [Group By Clause](../../../language-reference/queries/group-by-clause.md).
25-
26-
The examples in this topic use the Northwind sample database. If you do not have this database on your development computer, you can download it from the Microsoft Download Center. For instructions, see [Downloading Sample Databases](../../../../framework/data/adonet/sql/linq/downloading-sample-databases.md).
27-
28-
[!INCLUDE[note_settings_general](~/includes/note-settings-general-md.md)]
29-
30-
### To create a connection to a database
31-
32-
1. In Visual Studio, open **Server Explorer**/**Database Explorer** by clicking **Server Explorer**/**Database Explorer** on the **View** menu.
33-
34-
2. Right-click **Data Connections** in **Server Explorer**/**Database Explorer** and then click **Add Connection**.
35-
36-
3. Specify a valid connection to the Northwind sample database.
37-
38-
### To add a project that contains a LINQ to SQL file
39-
40-
1. In Visual Studio, on the **File** menu, point to **New** and then click **Project**. Select Visual Basic **Windows Forms Application** as the project type.
41-
42-
2. On the **Project** menu, click **Add New Item**. Select the **LINQ to SQL Classes** item template.
43-
44-
3. Name the file `northwind.dbml`. Click **Add**. The Object Relational Designer (O/R Designer) is opened for the northwind.dbml file.
45-
46-
### To add tables to query to the O/R Designer
47-
48-
1. In **Server Explorer**/**Database Explorer**, expand the connection to the Northwind database. Expand the **Tables** folder.
49-
50-
If you have closed the O/R Designer, you can reopen it by double-clicking the northwind.dbml file that you added earlier.
51-
52-
2. Click the Customers table and drag it to the left pane of the designer. Click the Orders table and drag it to the left pane of the designer.
53-
54-
The designer creates new `Customer` and `Order` objects for your project. Notice that the designer automatically detects relationships between the tables and creates child properties for related objects. For example, IntelliSense will show that the `Customer` object has an `Orders` property for all orders related to that customer.
55-
56-
3. Save your changes and close the designer.
57-
58-
4. Save your project.
59-
60-
### To add code to query the database and display the results
61-
62-
1. From the **Toolbox**, drag a <xref:System.Windows.Forms.DataGridView> control onto the default Windows Form for your project, Form1.
63-
64-
2. Double-click Form1 to add code to the `Load` event of the form.
65-
66-
3. When you added tables to the O/R Designer, the designer added a <xref:System.Data.Linq.DataContext> object for your project. This object contains the code that you must have to access those tables, and to access individual objects and collections for each table. The <xref:System.Data.Linq.DataContext> object for your project is named based on the name of your .dbml file. For this project, the <xref:System.Data.Linq.DataContext> object is named `northwindDataContext`.
67-
68-
You can create an instance of the <xref:System.Data.Linq.DataContext> in your code and query the tables specified by the O/R Designer.
69-
70-
Add the following code to the `Load` event to query the tables that are exposed as properties of your <xref:System.Data.Linq.DataContext> and count, sum, and average the results. The sample uses the `Aggregate` clause to query for a single result, and the `Group By` clause to show an average for grouped results.
71-
72-
[!code-vb[VbLINQToSQLHowTos#13](~/samples/snippets/visualbasic/VS_Snippets_VBCSharp/VbLINQtoSQLHowTos/VB/Form6.vb#13)]
73-
74-
4. Press F5 to run your project and view the results.
75-
22+
Language-Integrated Query (LINQ) makes it easy to access database information and execute queries.
23+
24+
The following example shows how to create a new application that performs queries against a SQL Server database. The sample counts, sums, and averages the results by using the `Aggregate` and `Group By` clauses. For more information, see [Aggregate Clause](../../../language-reference/queries/aggregate-clause.md) and [Group By Clause](../../../language-reference/queries/group-by-clause.md).
25+
26+
The examples in this article use the Northwind sample database. To obtain the database, see [Downloading Sample Databases](../../../../framework/data/adonet/sql/linq/downloading-sample-databases.md)..
27+
28+
[!INCLUDE[note_settings_general](~/includes/note-settings-general-md.md)]
29+
30+
### To create a connection to a database
31+
32+
1. In Visual Studio, open **Server Explorer**/**Database Explorer** by clicking **Server Explorer**/**Database Explorer** on the **View** menu.
33+
34+
2. Right-click **Data Connections** in **Server Explorer**/**Database Explorer** and then click **Add Connection**.
35+
36+
3. Specify a valid connection to the Northwind sample database.
37+
38+
### To add a project that contains a LINQ to SQL file
39+
40+
1. In Visual Studio, on the **File** menu, point to **New** and then click **Project**. Select Visual Basic **Windows Forms Application** as the project type.
41+
42+
2. On the **Project** menu, click **Add New Item**. Select the **LINQ to SQL Classes** item template.
43+
44+
3. Name the file `northwind.dbml`. Click **Add**. The Object Relational Designer (O/R Designer) is opened for the northwind.dbml file.
45+
46+
### To add tables to query to the O/R Designer
47+
48+
1. In **Server Explorer**/**Database Explorer**, expand the connection to the Northwind database. Expand the **Tables** folder.
49+
50+
If you have closed the O/R Designer, you can reopen it by double-clicking the northwind.dbml file that you added earlier.
51+
52+
2. Click the Customers table and drag it to the left pane of the designer. Click the Orders table and drag it to the left pane of the designer.
53+
54+
The designer creates new `Customer` and `Order` objects for your project. Notice that the designer automatically detects relationships between the tables and creates child properties for related objects. For example, IntelliSense will show that the `Customer` object has an `Orders` property for all orders related to that customer.
55+
56+
3. Save your changes and close the designer.
57+
58+
4. Save your project.
59+
60+
### To add code to query the database and display the results
61+
62+
1. From the **Toolbox**, drag a <xref:System.Windows.Forms.DataGridView> control onto the default Windows Form for your project, Form1.
63+
64+
2. Double-click Form1 to add code to the `Load` event of the form.
65+
66+
3. When you added tables to the O/R Designer, the designer added a <xref:System.Data.Linq.DataContext> object for your project. This object contains the code that you must have to access those tables, and to access individual objects and collections for each table. The <xref:System.Data.Linq.DataContext> object for your project is named based on the name of your .dbml file. For this project, the <xref:System.Data.Linq.DataContext> object is named `northwindDataContext`.
67+
68+
You can create an instance of the <xref:System.Data.Linq.DataContext> in your code and query the tables specified by the O/R Designer.
69+
70+
Add the following code to the `Load` event to query the tables that are exposed as properties of your <xref:System.Data.Linq.DataContext> and count, sum, and average the results. The sample uses the `Aggregate` clause to query for a single result, and the `Group By` clause to show an average for grouped results.
71+
72+
[!code-vb[VbLINQToSQLHowTos#13](~/samples/snippets/visualbasic/VS_Snippets_VBCSharp/VbLINQtoSQLHowTos/VB/Form6.vb#13)]
73+
74+
4. Press F5 to run your project and view the results.
75+
7676
## See also
7777

7878
- [LINQ](index.md)

docs/visual-basic/programming-guide/language-features/linq/how-to-filter-query-results-by-using-linq.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ Language-Integrated Query (LINQ) makes it easy to access database information an
1919

2020
The following example shows how to create a new application that performs queries against a SQL Server database and filters the results by a particular value by using the `Where` clause. For more information, see [Where Clause](../../../language-reference/queries/where-clause.md).
2121

22-
The examples in this topic use the Northwind sample database. If you do not have this database on your development computer, you can download it from the Microsoft Download Center. For instructions, see [Downloading Sample Databases](../../../../framework/data/adonet/sql/linq/downloading-sample-databases.md).
22+
The examples in this article use the Northwind sample database. To obtain the database, see [Downloading Sample Databases](../../../../framework/data/adonet/sql/linq/downloading-sample-databases.md).
2323

2424
[!INCLUDE[note_settings_general](~/includes/note-settings-general-md.md)]
2525

0 commit comments

Comments
 (0)