diff --git a/docs/visual-basic/programming-guide/language-features/linq/how-to-call-a-stored-procedure-by-using-linq.md b/docs/visual-basic/programming-guide/language-features/linq/how-to-call-a-stored-procedure-by-using-linq.md index 6627c984dc868..970991a13f08e 100644 --- a/docs/visual-basic/programming-guide/language-features/linq/how-to-call-a-stored-procedure-by-using-linq.md +++ b/docs/visual-basic/programming-guide/language-features/linq/how-to-call-a-stored-procedure-by-using-linq.md @@ -2,7 +2,7 @@ description: "Learn more about: How to: Call a Stored Procedure by Using LINQ (Visual Basic)" title: "How to: Call a Stored Procedure by Using LINQ" ms.date: 07/20/2015 -helpviewer_keywords: +helpviewer_keywords: - "queries [LINQ in Visual Basic], stored procedure calls" - "stored procedures sample [Visual Basic]" - "stored procedures [LINQ to SQL]" @@ -11,59 +11,59 @@ ms.assetid: 6436d384-d1e0-40aa-8afd-451007477260 --- # How to: Call a Stored Procedure by Using LINQ (Visual Basic) -Language-Integrated Query (LINQ) makes it easy to access database information, including database objects such as stored procedures. - - 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. - - 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). - -[!INCLUDE[note_settings_general](~/includes/note-settings-general-md.md)] - -### To create a connection to a database - -1. In Visual Studio, open **Server Explorer**/**Database Explorer** by clicking **Server Explorer**/**Database Explorer** on the **View** menu. - -2. Right-click **Data Connections** in **Server Explorer**/**Database Explorer** and then click **Add Connection**. - -3. Specify a valid connection to the Northwind sample database. - -### To add a project that contains a LINQ to SQL file - -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. - -2. On the **Project** menu, click **Add New Item**. Select the **LINQ to SQL Classes** item template. - -3. Name the file `northwind.dbml`. Click **Add**. The Object Relational Designer (O/R Designer) is opened for the northwind.dbml file. - -### To add stored procedures to the O/R Designer - -1. In **Server Explorer**/**Database Explorer**, expand the connection to the Northwind database. Expand the **Stored Procedures** folder. - - If you have closed the O/R Designer, you can reopen it by double-clicking the northwind.dbml file that you added earlier. - -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. - -3. Save your changes and close the designer. - -4. Save your project. - -### To add code to display the results of the stored procedures - -1. From the **Toolbox**, drag a control onto the default Windows Form for your project, Form1. - -2. Double-click Form1 to add code to its `Load` event. - -3. When you added stored procedures to the O/R Designer, the designer added a object for your project. This object contains the code that you must have to access those procedures. The object for the project is named based on the name of the .dbml file. For this project, the object is named `northwindDataContext`. - - You can create an instance of the in your code and call the stored procedure methods specified by the O/R Designer. To bind to the object, you may have to force the query to execute immediately by calling the method on the results of the stored procedure. - - Add the following code to the `Load` event to call either of the stored procedures exposed as methods for your data context. - - [!code-vb[VbLINQtoSQLHowTos#1](~/samples/snippets/visualbasic/VS_Snippets_VBCSharp/VbLINQtoSQLHowTos/VB/Form3.vb#1)] - [!code-vb[VbLINQtoSQLHowTos#2](~/samples/snippets/visualbasic/VS_Snippets_VBCSharp/VbLINQtoSQLHowTos/VB/Form3.vb#2)] - -4. Press F5 to run your project and view the results. - +Language-Integrated Query (LINQ) makes it easy to access database information, including database objects such as stored procedures. + + 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. + +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). + +[!INCLUDE[note_settings_general](~/includes/note-settings-general-md.md)] + +## To create a connection to a database + +1. In Visual Studio, open **Server Explorer**/**Database Explorer** by clicking **Server Explorer**/**Database Explorer** on the **View** menu. + +2. Right-click **Data Connections** in **Server Explorer**/**Database Explorer** and then click **Add Connection**. + +3. Specify a valid connection to the Northwind sample database. + +## To add a project that contains a LINQ to SQL file + +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. + +2. On the **Project** menu, click **Add New Item**. Select the **LINQ to SQL Classes** item template. + +3. Name the file `northwind.dbml`. Click **Add**. The Object Relational Designer (O/R Designer) is opened for the northwind.dbml file. + +## To add stored procedures to the O/R Designer + +1. In **Server Explorer**/**Database Explorer**, expand the connection to the Northwind database. Expand the **Stored Procedures** folder. + + If you have closed the O/R Designer, you can reopen it by double-clicking the northwind.dbml file that you added earlier. + +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. + +3. Save your changes and close the designer. + +4. Save your project. + +## To add code to display the results of the stored procedures + +1. From the **Toolbox**, drag a control onto the default Windows Form for your project, Form1. + +2. Double-click Form1 to add code to its `Load` event. + +3. When you added stored procedures to the O/R Designer, the designer added a object for your project. This object contains the code that you must have to access those procedures. The object for the project is named based on the name of the .dbml file. For this project, the object is named `northwindDataContext`. + + You can create an instance of the in your code and call the stored procedure methods specified by the O/R Designer. To bind to the object, you may have to force the query to execute immediately by calling the method on the results of the stored procedure. + + Add the following code to the `Load` event to call either of the stored procedures exposed as methods for your data context. + + [!code-vb[VbLINQtoSQLHowTos#1](~/samples/snippets/visualbasic/VS_Snippets_VBCSharp/VbLINQtoSQLHowTos/VB/Form3.vb#1)] + [!code-vb[VbLINQtoSQLHowTos#2](~/samples/snippets/visualbasic/VS_Snippets_VBCSharp/VbLINQtoSQLHowTos/VB/Form3.vb#2)] + +4. Press F5 to run your project and view the results. + ## See also - [LINQ](index.md) diff --git a/docs/visual-basic/programming-guide/language-features/linq/how-to-count-sum-or-average-data-by-using-linq.md b/docs/visual-basic/programming-guide/language-features/linq/how-to-count-sum-or-average-data-by-using-linq.md index df6785de5593f..c1e8cb1083745 100644 --- a/docs/visual-basic/programming-guide/language-features/linq/how-to-count-sum-or-average-data-by-using-linq.md +++ b/docs/visual-basic/programming-guide/language-features/linq/how-to-count-sum-or-average-data-by-using-linq.md @@ -2,7 +2,7 @@ description: "Learn more about: How to: Count, Sum, or Average Data by Using LINQ (Visual Basic)" title: "How to: Count, Sum, or Average Data by Using LINQ" ms.date: 07/20/2015 -helpviewer_keywords: +helpviewer_keywords: - "average operator [LINQ in Visual Basic]" - "aggregate operator [LINQ in Visual Basic]" - "aggregate queries" @@ -19,60 +19,60 @@ ms.assetid: 51ca1f59-7770-4884-8b76-113002e54fc0 --- # How to: Count, Sum, or Average Data by Using LINQ (Visual Basic) -Language-Integrated Query (LINQ) makes it easy to access database information and execute queries. - - 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). - - 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). - -[!INCLUDE[note_settings_general](~/includes/note-settings-general-md.md)] - -### To create a connection to a database - -1. In Visual Studio, open **Server Explorer**/**Database Explorer** by clicking **Server Explorer**/**Database Explorer** on the **View** menu. - -2. Right-click **Data Connections** in **Server Explorer**/**Database Explorer** and then click **Add Connection**. - -3. Specify a valid connection to the Northwind sample database. - -### To add a project that contains a LINQ to SQL file - -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. - -2. On the **Project** menu, click **Add New Item**. Select the **LINQ to SQL Classes** item template. - -3. Name the file `northwind.dbml`. Click **Add**. The Object Relational Designer (O/R Designer) is opened for the northwind.dbml file. - -### To add tables to query to the O/R Designer - -1. In **Server Explorer**/**Database Explorer**, expand the connection to the Northwind database. Expand the **Tables** folder. - - If you have closed the O/R Designer, you can reopen it by double-clicking the northwind.dbml file that you added earlier. - -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. - - 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. - -3. Save your changes and close the designer. - -4. Save your project. - -### To add code to query the database and display the results - -1. From the **Toolbox**, drag a control onto the default Windows Form for your project, Form1. - -2. Double-click Form1 to add code to the `Load` event of the form. - -3. When you added tables to the O/R Designer, the designer added a 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 object for your project is named based on the name of your .dbml file. For this project, the object is named `northwindDataContext`. - - You can create an instance of the in your code and query the tables specified by the O/R Designer. - - Add the following code to the `Load` event to query the tables that are exposed as properties of your 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. - - [!code-vb[VbLINQToSQLHowTos#13](~/samples/snippets/visualbasic/VS_Snippets_VBCSharp/VbLINQtoSQLHowTos/VB/Form6.vb#13)] - -4. Press F5 to run your project and view the results. - +Language-Integrated Query (LINQ) makes it easy to access database information and execute queries. + + 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). + +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).. + +[!INCLUDE[note_settings_general](~/includes/note-settings-general-md.md)] + +### To create a connection to a database + +1. In Visual Studio, open **Server Explorer**/**Database Explorer** by clicking **Server Explorer**/**Database Explorer** on the **View** menu. + +2. Right-click **Data Connections** in **Server Explorer**/**Database Explorer** and then click **Add Connection**. + +3. Specify a valid connection to the Northwind sample database. + +### To add a project that contains a LINQ to SQL file + +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. + +2. On the **Project** menu, click **Add New Item**. Select the **LINQ to SQL Classes** item template. + +3. Name the file `northwind.dbml`. Click **Add**. The Object Relational Designer (O/R Designer) is opened for the northwind.dbml file. + +### To add tables to query to the O/R Designer + +1. In **Server Explorer**/**Database Explorer**, expand the connection to the Northwind database. Expand the **Tables** folder. + + If you have closed the O/R Designer, you can reopen it by double-clicking the northwind.dbml file that you added earlier. + +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. + + 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. + +3. Save your changes and close the designer. + +4. Save your project. + +### To add code to query the database and display the results + +1. From the **Toolbox**, drag a control onto the default Windows Form for your project, Form1. + +2. Double-click Form1 to add code to the `Load` event of the form. + +3. When you added tables to the O/R Designer, the designer added a 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 object for your project is named based on the name of your .dbml file. For this project, the object is named `northwindDataContext`. + + You can create an instance of the in your code and query the tables specified by the O/R Designer. + + Add the following code to the `Load` event to query the tables that are exposed as properties of your 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. + + [!code-vb[VbLINQToSQLHowTos#13](~/samples/snippets/visualbasic/VS_Snippets_VBCSharp/VbLINQtoSQLHowTos/VB/Form6.vb#13)] + +4. Press F5 to run your project and view the results. + ## See also - [LINQ](index.md) diff --git a/docs/visual-basic/programming-guide/language-features/linq/how-to-filter-query-results-by-using-linq.md b/docs/visual-basic/programming-guide/language-features/linq/how-to-filter-query-results-by-using-linq.md index de31c893ccc33..77e9f130ec075 100644 --- a/docs/visual-basic/programming-guide/language-features/linq/how-to-filter-query-results-by-using-linq.md +++ b/docs/visual-basic/programming-guide/language-features/linq/how-to-filter-query-results-by-using-linq.md @@ -19,7 +19,7 @@ Language-Integrated Query (LINQ) makes it easy to access database information an 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). -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). +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). [!INCLUDE[note_settings_general](~/includes/note-settings-general-md.md)] diff --git a/docs/visual-basic/programming-guide/language-features/linq/how-to-find-the-minimum-or-maximum-value-in-a-query-result.md b/docs/visual-basic/programming-guide/language-features/linq/how-to-find-the-minimum-or-maximum-value-in-a-query-result.md index 1ddda41ba81ff..7d96037ce09f1 100644 --- a/docs/visual-basic/programming-guide/language-features/linq/how-to-find-the-minimum-or-maximum-value-in-a-query-result.md +++ b/docs/visual-basic/programming-guide/language-features/linq/how-to-find-the-minimum-or-maximum-value-in-a-query-result.md @@ -2,7 +2,7 @@ description: "Learn more about: How to: Find the Minimum or Maximum Value in a Query Result by Using LINQ (Visual Basic)" title: "How to: Find the Minimum or Maximum Value in a Query Result by Using LINQ" ms.date: 07/20/2015 -helpviewer_keywords: +helpviewer_keywords: - "max operator [LINQ in Visual Basic]" - "aggregate operator [LINQ in Visual Basic]" - "aggregate queries" @@ -18,60 +18,60 @@ ms.assetid: 238b763b-7dcd-4b14-8050-b65500a4f71c --- # How to: Find the Minimum or Maximum Value in a Query Result by Using LINQ (Visual Basic) -Language-Integrated Query (LINQ) makes it easy to access database information and execute queries. - - The following example shows how to create a new application that performs queries against a SQL Server database. The sample determines the minimum and maximum values for 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). - - 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). - -[!INCLUDE[note_settings_general](~/includes/note-settings-general-md.md)] - -## Create a connection to a database - -1. In Visual Studio, open **Server Explorer**/**Database Explorer** by clicking **Server Explorer**/**Database Explorer** on the **View** menu. - -2. Right-click **Data Connections** in **Server Explorer**/**Database Explorer** and then click **Add Connection**. - -3. Specify a valid connection to the Northwind sample database. - -### To add a project that contains a LINQ to SQL file - -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. - -2. On the **Project** menu, click **Add New Item**. Select the **LINQ to SQL Classes** item template. - -3. Name the file `northwind.dbml`. Click **Add**. The Object Relational Designer (O/R Designer) is opened for the northwind.dbml file. - -## Add tables to query to the O/R Designer - -1. In **Server Explorer**/**Database Explorer**, expand the connection to the Northwind database. Expand the **Tables** folder. - - If you have closed the O/R Designer, you can reopen it by double-clicking the northwind.dbml file that you added earlier. - -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. - - 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. - -3. Save your changes and close the designer. - -4. Save your project. - -## Add code to query the database and display the results - -1. From the **Toolbox**, drag a control onto the default Windows Form for your project, Form1. - -2. Double-click Form1 to add code to the `Load` event of the form. - -3. When you added tables to the O/R Designer, the designer added a object for your project. This object contains the code that you must have to access those tables, in addition to individual objects and collections for each table. The object for your project is named based on the name of your .dbml file. For this project, the object is named `northwindDataContext`. - - You can create an instance of the in your code and query the tables specified by the O/R Designer. - - Add the following code to the `Load` event. This code queries the tables that are exposed as properties of your data context and determines the minimum and maximum values for 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. - - [!code-vb[VbLINQToSQLHowTos#14](~/samples/snippets/visualbasic/VS_Snippets_VBCSharp/VbLINQtoSQLHowTos/VB/Form7.vb#14)] - -4. Press F5 to run your project and view the results. - +Language-Integrated Query (LINQ) makes it easy to access database information and execute queries. + + The following example shows how to create a new application that performs queries against a SQL Server database. The sample determines the minimum and maximum values for 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). + +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). + +[!INCLUDE[note_settings_general](~/includes/note-settings-general-md.md)] + +## Create a connection to a database + +1. In Visual Studio, open **Server Explorer**/**Database Explorer** by clicking **Server Explorer**/**Database Explorer** on the **View** menu. + +2. Right-click **Data Connections** in **Server Explorer**/**Database Explorer** and then click **Add Connection**. + +3. Specify a valid connection to the Northwind sample database. + +### To add a project that contains a LINQ to SQL file + +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. + +2. On the **Project** menu, click **Add New Item**. Select the **LINQ to SQL Classes** item template. + +3. Name the file `northwind.dbml`. Click **Add**. The Object Relational Designer (O/R Designer) is opened for the northwind.dbml file. + +## Add tables to query to the O/R Designer + +1. In **Server Explorer**/**Database Explorer**, expand the connection to the Northwind database. Expand the **Tables** folder. + + If you have closed the O/R Designer, you can reopen it by double-clicking the northwind.dbml file that you added earlier. + +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. + + 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. + +3. Save your changes and close the designer. + +4. Save your project. + +## Add code to query the database and display the results + +1. From the **Toolbox**, drag a control onto the default Windows Form for your project, Form1. + +2. Double-click Form1 to add code to the `Load` event of the form. + +3. When you added tables to the O/R Designer, the designer added a object for your project. This object contains the code that you must have to access those tables, in addition to individual objects and collections for each table. The object for your project is named based on the name of your .dbml file. For this project, the object is named `northwindDataContext`. + + You can create an instance of the in your code and query the tables specified by the O/R Designer. + + Add the following code to the `Load` event. This code queries the tables that are exposed as properties of your data context and determines the minimum and maximum values for 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. + + [!code-vb[VbLINQToSQLHowTos#14](~/samples/snippets/visualbasic/VS_Snippets_VBCSharp/VbLINQtoSQLHowTos/VB/Form7.vb#14)] + +4. Press F5 to run your project and view the results. + ## See also - [LINQ](index.md) diff --git a/docs/visual-basic/programming-guide/language-features/linq/how-to-modify-data-in-a-database-by-using-linq.md b/docs/visual-basic/programming-guide/language-features/linq/how-to-modify-data-in-a-database-by-using-linq.md index fad63ddf1f113..7ddf83db4da9a 100644 --- a/docs/visual-basic/programming-guide/language-features/linq/how-to-modify-data-in-a-database-by-using-linq.md +++ b/docs/visual-basic/programming-guide/language-features/linq/how-to-modify-data-in-a-database-by-using-linq.md @@ -20,7 +20,7 @@ Language-Integrated Query (LINQ) queries make it easy to access database informa The following example shows how to create a new application that retrieves and updates information in a SQL Server database. -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). +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). ### To create a connection to a database diff --git a/docs/visual-basic/programming-guide/language-features/linq/how-to-query-a-database-by-using-linq.md b/docs/visual-basic/programming-guide/language-features/linq/how-to-query-a-database-by-using-linq.md index 217bc25518fcd..48948a6e88d17 100644 --- a/docs/visual-basic/programming-guide/language-features/linq/how-to-query-a-database-by-using-linq.md +++ b/docs/visual-basic/programming-guide/language-features/linq/how-to-query-a-database-by-using-linq.md @@ -2,7 +2,7 @@ description: "Learn more about: How to: Query a Database by Using LINQ (Visual Basic)" title: "How to: Query a Database by Using LINQ" ms.date: 07/20/2015 -helpviewer_keywords: +helpviewer_keywords: - "query samples [LINQ]" - "database querying [LINQ]" - "queries [LINQ in Visual Basic], database querying" @@ -13,65 +13,65 @@ ms.assetid: bcf5e9c3-a236-4399-9a7f-3991eca7cf56 --- # How to: Query a Database by Using LINQ (Visual Basic) -Language-Integrated Query (LINQ) makes it easy to access database information and execute queries. - - The following example shows how to create a new application that performs queries against a SQL Server database. - - 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). - -[!INCLUDE[note_settings_general](~/includes/note-settings-general-md.md)] - -## To create a connection to a database - -1. In Visual Studio, open **Server Explorer**/**Database Explorer** by clicking **Server Explorer**/**Database Explorer** on the **View** menu. - -2. Right-click **Data Connections** in **Server Explorer**/**Database Explorer** and then click **Add Connection**. - -3. Specify a valid connection to the Northwind sample database. - -## To add a project that contains a LINQ to SQL file - -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. - -2. On the **Project** menu, click **Add New Item**. Select the **LINQ to SQL Classes** item template. - -3. Name the file `northwind.dbml`. Click **Add**. The Object Relational Designer (O/R Designer) is opened for the northwind.dbml file. - -## To add tables to query to the O/R Designer - -1. In **Server Explorer**/**Database Explorer**, expand the connection to the Northwind database. Expand the **Tables** folder. - - If you have closed the O/R Designer, you can reopen it by double-clicking the northwind.dbml file that you added earlier. - -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. - - 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. - -3. Save your changes and close the designer. - -4. Save your project. - -## To add code to query the database and display the results - -1. From the **Toolbox**, drag a control onto the default Windows Form for your project, Form1. - -2. Double-click Form1 to add code to the `Load` event of the form. - -3. When you added tables to the O/R Designer, the designer added a object for your project. This object contains the code that you must have to access those tables, in addition to individual objects and collections for each table. The object for your project is named based on the name of your .dbml file. For this project, the object is named `northwindDataContext`. - - You can create an instance of the in your code and query the tables specified by the O/R Designer. - - Add the following code to the `Load` event to query the tables that are exposed as properties of your data context. - - [!code-vb[VbLINQToSQLHowTos#3](~/samples/snippets/visualbasic/VS_Snippets_VBCSharp/VbLINQtoSQLHowTos/VB/Form2.vb#3)] - -4. Press F5 to run your project and view the results. - -5. Following are some additional queries that you can try: - - [!code-vb[VbLINQToSQLHowTos#4](~/samples/snippets/visualbasic/VS_Snippets_VBCSharp/VbLINQtoSQLHowTos/VB/Form2.vb#4)] - [!code-vb[VbLINQToSQLHowTos#5](~/samples/snippets/visualbasic/VS_Snippets_VBCSharp/VbLINQtoSQLHowTos/VB/Form2.vb#5)] - +Language-Integrated Query (LINQ) makes it easy to access database information and execute queries. + + The following example shows how to create a new application that performs queries against a SQL Server database. + +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). + +[!INCLUDE[note_settings_general](~/includes/note-settings-general-md.md)] + +## To create a connection to a database + +1. In Visual Studio, open **Server Explorer**/**Database Explorer** by clicking **Server Explorer**/**Database Explorer** on the **View** menu. + +2. Right-click **Data Connections** in **Server Explorer**/**Database Explorer** and then click **Add Connection**. + +3. Specify a valid connection to the Northwind sample database. + +## To add a project that contains a LINQ to SQL file + +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. + +2. On the **Project** menu, click **Add New Item**. Select the **LINQ to SQL Classes** item template. + +3. Name the file `northwind.dbml`. Click **Add**. The Object Relational Designer (O/R Designer) is opened for the northwind.dbml file. + +## To add tables to query to the O/R Designer + +1. In **Server Explorer**/**Database Explorer**, expand the connection to the Northwind database. Expand the **Tables** folder. + + If you have closed the O/R Designer, you can reopen it by double-clicking the northwind.dbml file that you added earlier. + +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. + + 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. + +3. Save your changes and close the designer. + +4. Save your project. + +## To add code to query the database and display the results + +1. From the **Toolbox**, drag a control onto the default Windows Form for your project, Form1. + +2. Double-click Form1 to add code to the `Load` event of the form. + +3. When you added tables to the O/R Designer, the designer added a object for your project. This object contains the code that you must have to access those tables, in addition to individual objects and collections for each table. The object for your project is named based on the name of your .dbml file. For this project, the object is named `northwindDataContext`. + + You can create an instance of the in your code and query the tables specified by the O/R Designer. + + Add the following code to the `Load` event to query the tables that are exposed as properties of your data context. + + [!code-vb[VbLINQToSQLHowTos#3](~/samples/snippets/visualbasic/VS_Snippets_VBCSharp/VbLINQtoSQLHowTos/VB/Form2.vb#3)] + +4. Press F5 to run your project and view the results. + +5. Following are some additional queries that you can try: + + [!code-vb[VbLINQToSQLHowTos#4](~/samples/snippets/visualbasic/VS_Snippets_VBCSharp/VbLINQtoSQLHowTos/VB/Form2.vb#4)] + [!code-vb[VbLINQToSQLHowTos#5](~/samples/snippets/visualbasic/VS_Snippets_VBCSharp/VbLINQtoSQLHowTos/VB/Form2.vb#5)] + ## See also - [LINQ](index.md) diff --git a/docs/visual-basic/programming-guide/language-features/linq/how-to-return-a-linq-query-result-as-a-specific-type.md b/docs/visual-basic/programming-guide/language-features/linq/how-to-return-a-linq-query-result-as-a-specific-type.md index 3ed6e1e765980..93f04b2458c57 100644 --- a/docs/visual-basic/programming-guide/language-features/linq/how-to-return-a-linq-query-result-as-a-specific-type.md +++ b/docs/visual-basic/programming-guide/language-features/linq/how-to-return-a-linq-query-result-as-a-specific-type.md @@ -2,7 +2,7 @@ description: "Learn more about: How to: Return a LINQ Query Result as a Specific Type (Visual Basic)" title: "How to: Return a LINQ Query Result as a Specific Type" ms.date: 07/20/2015 -helpviewer_keywords: +helpviewer_keywords: - "queries [LINQ in Visual Basic], specific type returned" - "projection [LINQ in Visual Basic]" - "anonymous types [Visual Basic]" @@ -13,64 +13,64 @@ ms.assetid: 621bb10a-e5d7-44fb-a025-317964b19d92 --- # How to: Return a LINQ Query Result as a Specific Type (Visual Basic) -Language-Integrated Query (LINQ) makes it easy to access database information and execute queries. By default, LINQ queries return a list of objects as an anonymous type. You can also specify that a query return a list of a specific type by using the `Select` clause. - - The following example shows how to create a new application that performs queries against a SQL Server database and projects the results as a specific named type. For more information, see [Anonymous Types](../objects-and-classes/anonymous-types.md) and [Select Clause](../../../language-reference/queries/select-clause.md). - - 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). - -[!INCLUDE[note_settings_general](~/includes/note-settings-general-md.md)] - -### To create a connection to a database - -1. In Visual Studio, open **Server Explorer**/**Database Explorer** by clicking **Server Explorer**/**Database Explorer** on the **View** menu. - -2. Right-click **Data Connections** in **Server Explorer**/**Database Explorer** and then click **Add Connection**. - -3. Specify a valid connection to the Northwind sample database. - -### To add a project that contains a LINQ to SQL file - -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. - -2. On the **Project** menu, click **Add New Item**. Select the **LINQ to SQL Classes** item template. - -3. Name the file `northwind.dbml`. Click **Add**. The Object Relational Designer (O/R Designer) is opened for the northwind.dbml file. - -### To add tables to query to the O/R Designer - -1. In **Server Explorer**/**Database Explorer**, expand the connection to the Northwind database. Expand the **Tables** folder. - - If you have closed the O/R Designer, you can reopen it by double-clicking the northwind.dbml file that you added earlier. - -2. Click the Customers table and drag it to the left pane of the designer. - - The designer creates a new `Customer` object for your project. You can project a query result as the `Customer` type or as a type that you create. This sample will create a new type in a later procedure and project a query result as that type. - -3. Save your changes and close the designer. - -4. Save your project. - -### To add code to query the database and display the results - -1. From the **Toolbox**, drag a control onto the default Windows Form for your project, Form1. - -2. Double-click Form1 to modify the Form1 class. - -3. After the `End Class` statement of the Form1 class, add the following code to create a `CustomerInfo` type to hold the query results for this sample. - - [!code-vb[VbLINQToSQLHowTos#16](~/samples/snippets/visualbasic/VS_Snippets_VBCSharp/VbLINQtoSQLHowTos/VB/Form8.vb#16)] - -4. When you added tables to the O/R Designer, the designer added a object to 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 object for your project is named based on the name of your .dbml file. For this project, the object is named `northwindDataContext`. - - You can create an instance of the in your code and query the tables specified by the O/R Designer. - - In the `Load` event of the Form1 class, add the following code to query the tables that are exposed as properties of your data context. The `Select` clause of the query will create a new `CustomerInfo` type instead of an anonymous type for each item of the query result. - - [!code-vb[VbLINQToSQLHowTos#15](~/samples/snippets/visualbasic/VS_Snippets_VBCSharp/VbLINQtoSQLHowTos/VB/Form8.vb#15)] - -5. Press F5 to run your project and view the results. - +Language-Integrated Query (LINQ) makes it easy to access database information and execute queries. By default, LINQ queries return a list of objects as an anonymous type. You can also specify that a query return a list of a specific type by using the `Select` clause. + + The following example shows how to create a new application that performs queries against a SQL Server database and projects the results as a specific named type. For more information, see [Anonymous Types](../objects-and-classes/anonymous-types.md) and [Select Clause](../../../language-reference/queries/select-clause.md). + +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). + +[!INCLUDE[note_settings_general](~/includes/note-settings-general-md.md)] + +### To create a connection to a database + +1. In Visual Studio, open **Server Explorer**/**Database Explorer** by clicking **Server Explorer**/**Database Explorer** on the **View** menu. + +2. Right-click **Data Connections** in **Server Explorer**/**Database Explorer** and then click **Add Connection**. + +3. Specify a valid connection to the Northwind sample database. + +### To add a project that contains a LINQ to SQL file + +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. + +2. On the **Project** menu, click **Add New Item**. Select the **LINQ to SQL Classes** item template. + +3. Name the file `northwind.dbml`. Click **Add**. The Object Relational Designer (O/R Designer) is opened for the northwind.dbml file. + +### To add tables to query to the O/R Designer + +1. In **Server Explorer**/**Database Explorer**, expand the connection to the Northwind database. Expand the **Tables** folder. + + If you have closed the O/R Designer, you can reopen it by double-clicking the northwind.dbml file that you added earlier. + +2. Click the Customers table and drag it to the left pane of the designer. + + The designer creates a new `Customer` object for your project. You can project a query result as the `Customer` type or as a type that you create. This sample will create a new type in a later procedure and project a query result as that type. + +3. Save your changes and close the designer. + +4. Save your project. + +### To add code to query the database and display the results + +1. From the **Toolbox**, drag a control onto the default Windows Form for your project, Form1. + +2. Double-click Form1 to modify the Form1 class. + +3. After the `End Class` statement of the Form1 class, add the following code to create a `CustomerInfo` type to hold the query results for this sample. + + [!code-vb[VbLINQToSQLHowTos#16](~/samples/snippets/visualbasic/VS_Snippets_VBCSharp/VbLINQtoSQLHowTos/VB/Form8.vb#16)] + +4. When you added tables to the O/R Designer, the designer added a object to 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 object for your project is named based on the name of your .dbml file. For this project, the object is named `northwindDataContext`. + + You can create an instance of the in your code and query the tables specified by the O/R Designer. + + In the `Load` event of the Form1 class, add the following code to query the tables that are exposed as properties of your data context. The `Select` clause of the query will create a new `CustomerInfo` type instead of an anonymous type for each item of the query result. + + [!code-vb[VbLINQToSQLHowTos#15](~/samples/snippets/visualbasic/VS_Snippets_VBCSharp/VbLINQtoSQLHowTos/VB/Form8.vb#15)] + +5. Press F5 to run your project and view the results. + ## See also - [LINQ](index.md) diff --git a/docs/visual-basic/programming-guide/language-features/linq/how-to-sort-query-results-by-using-linq.md b/docs/visual-basic/programming-guide/language-features/linq/how-to-sort-query-results-by-using-linq.md index e51d77be90c31..20e752e3aaf6b 100644 --- a/docs/visual-basic/programming-guide/language-features/linq/how-to-sort-query-results-by-using-linq.md +++ b/docs/visual-basic/programming-guide/language-features/linq/how-to-sort-query-results-by-using-linq.md @@ -2,7 +2,7 @@ description: "Learn more about: How to: Sort Query Results by Using LINQ (Visual Basic)" title: "How to: Sort Query Results by Using LINQ" ms.date: 07/20/2015 -helpviewer_keywords: +helpviewer_keywords: - "sorting query results, multiple columns" - "sorting data [Visual Basic]" - "sorting data [LINQ in Visual Basic]" @@ -15,60 +15,60 @@ ms.assetid: 07a4584d-9fd8-4a1d-b7d9-ccf2efa5c84e --- # How to: Sort Query Results by Using LINQ (Visual Basic) -Language-Integrated Query (LINQ) makes it easy to access database information and execute queries. - - The following example shows how to create a new application that performs queries against a SQL Server database and sorts the results by multiple fields by using the `Order By` clause. The sort order for each field can be ascending order or descending order. For more information, see [Order By Clause](../../../language-reference/queries/order-by-clause.md). - - 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). - -[!INCLUDE[note_settings_general](~/includes/note-settings-general-md.md)] - -### To create a connection to a database - -1. In Visual Studio, open **Server Explorer**/**Database Explorer** by clicking **Server Explorer**/**Database Explorer** on the **View** menu. - -2. Right-click **Data Connections** in **Server Explorer**/**Database Explorer** and then click **Add Connection**. - -3. Specify a valid connection to the Northwind sample database. - -### To add a project that contains a LINQ to SQL file - -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. - -2. On the **Project** menu, click **Add New Item**. Select the **LINQ to SQL Classes** item template. - -3. Name the file `northwind.dbml`. Click **Add**. The Object Relational Designer (O/R Designer) is opened for the northwind.dbml file. - -### To add tables to query to the O/R Designer - -1. In **Server Explorer**/**Database Explorer**, expand the connection to the Northwind database. Expand the **Tables** folder. - - If you have closed the O/R Designer, you can reopen it by double-clicking the northwind.dbml file that you added earlier. - -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. - - 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. - -3. Save your changes and close the designer. - -4. Save your project. - -### To add code to query the database and display the results - -1. From the **Toolbox**, drag a control onto the default Windows Form for your project, Form1. - -2. Double-click Form1 to add code to the `Load` event of the form. - -3. When you added tables to the O/R Designer, the designer added a object to 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 object for your project is named based on the name of your .dbml file. For this project, the object is named `northwindDataContext`. - - You can create an instance of the in your code and query the tables specified by the O/R Designer. - - Add the following code to the `Load` event to query the tables that are exposed as properties of your data context and sort the results. The query sorts the results by the number of customer orders, in descending order. Customers that have the same number of orders are ordered by company name in ascending order (the default). - - [!code-vb[VbLINQToSQLHowTos#10](~/samples/snippets/visualbasic/VS_Snippets_VBCSharp/VbLINQtoSQLHowTos/VB/Form4.vb#10)] - -4. Press F5 to run your project and view the results. - +Language-Integrated Query (LINQ) makes it easy to access database information and execute queries. + + The following example shows how to create a new application that performs queries against a SQL Server database and sorts the results by multiple fields by using the `Order By` clause. The sort order for each field can be ascending order or descending order. For more information, see [Order By Clause](../../../language-reference/queries/order-by-clause.md). + +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). + +[!INCLUDE[note_settings_general](~/includes/note-settings-general-md.md)] + +### To create a connection to a database + +1. In Visual Studio, open **Server Explorer**/**Database Explorer** by clicking **Server Explorer**/**Database Explorer** on the **View** menu. + +2. Right-click **Data Connections** in **Server Explorer**/**Database Explorer** and then click **Add Connection**. + +3. Specify a valid connection to the Northwind sample database. + +### To add a project that contains a LINQ to SQL file + +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. + +2. On the **Project** menu, click **Add New Item**. Select the **LINQ to SQL Classes** item template. + +3. Name the file `northwind.dbml`. Click **Add**. The Object Relational Designer (O/R Designer) is opened for the northwind.dbml file. + +### To add tables to query to the O/R Designer + +1. In **Server Explorer**/**Database Explorer**, expand the connection to the Northwind database. Expand the **Tables** folder. + + If you have closed the O/R Designer, you can reopen it by double-clicking the northwind.dbml file that you added earlier. + +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. + + 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. + +3. Save your changes and close the designer. + +4. Save your project. + +### To add code to query the database and display the results + +1. From the **Toolbox**, drag a control onto the default Windows Form for your project, Form1. + +2. Double-click Form1 to add code to the `Load` event of the form. + +3. When you added tables to the O/R Designer, the designer added a object to 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 object for your project is named based on the name of your .dbml file. For this project, the object is named `northwindDataContext`. + + You can create an instance of the in your code and query the tables specified by the O/R Designer. + + Add the following code to the `Load` event to query the tables that are exposed as properties of your data context and sort the results. The query sorts the results by the number of customer orders, in descending order. Customers that have the same number of orders are ordered by company name in ascending order (the default). + + [!code-vb[VbLINQToSQLHowTos#10](~/samples/snippets/visualbasic/VS_Snippets_VBCSharp/VbLINQtoSQLHowTos/VB/Form4.vb#10)] + +4. Press F5 to run your project and view the results. + ## See also - [LINQ](index.md)