Walkthrough: Display Data from a SQL Server Database in a DataGrid Control

In this walkthrough, you retrieve data from a SQL Server database and display that data in a DataGrid control. You use the ADO.NET Entity Framework to create the entity classes that represent the data, and use LINQ to write a query that retrieves the specified data from an entity class.

Access to a running instance of SQL Server or SQL Server Express that has the AdventureWorksLT2008 sample database attached to it. You can download the AdventureWorksLT2008 database from the CodePlex Web site.

To create entity classes

Create a new WPF Application project in Visual Basic or C#, and name it DataGridSQLExample.

In Solution Explorer, right-click your project, point to Add, and then select New Item.

The Add New Item dialog box appears.

In the Installed Templates pane, select Data and in the list of templates, select ADO.NET Entity Data Model.

Name the file AdventureWorksModel.edmx and then click Add.

The Entity Data Model Wizard appears.

In the Choose Model Contents screen, select Generate from database and then click Next.