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/visual-basic/programming-guide/language-features/linq/how-to-call-a-stored-procedure-by-using-linq.md
+54-54Lines changed: 54 additions & 54 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -2,7 +2,7 @@
2
2
description: "Learn more about: How to: Call a Stored Procedure by Using LINQ (Visual Basic)"
3
3
title: "How to: Call a Stored Procedure by Using LINQ"
4
4
ms.date: 07/20/2015
5
-
helpviewer_keywords:
5
+
helpviewer_keywords:
6
6
- "queries [LINQ in Visual Basic], stored procedure calls"
# How to: Call a Stored Procedure by Using LINQ (Visual Basic)
13
13
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).
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.
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).
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.
Copy file name to clipboardExpand all lines: docs/visual-basic/programming-guide/language-features/linq/how-to-count-sum-or-average-data-by-using-linq.md
+55-55Lines changed: 55 additions & 55 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -2,7 +2,7 @@
2
2
description: "Learn more about: How to: Count, Sum, or Average Data by Using LINQ (Visual Basic)"
3
3
title: "How to: Count, Sum, or Average Data by Using LINQ"
# How to: Count, Sum, or Average Data by Using LINQ (Visual Basic)
21
21
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).
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.
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)..
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.
Copy file name to clipboardExpand all lines: docs/visual-basic/programming-guide/language-features/linq/how-to-filter-query-results-by-using-linq.md
+1-1Lines changed: 1 addition & 1 deletion
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -19,7 +19,7 @@ Language-Integrated Query (LINQ) makes it easy to access database information an
19
19
20
20
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).
21
21
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).
0 commit comments