Chapter 8: Building Desktop Applications with WPF

235

following sections show you how to perform create, read, update, and delete (CRUD) operations via WPF. You’ll first see how to insert data, using VS tools to construct a data entry screen. Then you’ll learn how to read, modify, and delete data through a DataGrid. We’ll start with single value binding. To make the examples more interesting, I added extra fields to the tables. You can review Chapter 7 to learn how to add fields to a database and create a LINQ to SQL entity model.

Setting Up a Data Source

Before you can bind to data in the window, you’ll need a data source to work with data. To get started, update the Order table, created in Chapter 7, so that it has the following fields:

OrderID, int, primary key, auto-increment

CustomerID, int

OrderDate, datetime

Location, varchar(50)

Amount, money

Then update the Customer table with the following fields:

CustomerID, int, primary key, auto-increment

Name, nvarchar(50)

Age, int

Birthday, datetime

Income, money

With the database updated, you can add a LINQ to SQL entity model to the project, using the same techniques described in Chapter 7.

To add the data source for binding, open the NewOrder window in the Designer, and select the Data Add New Data Source menu, which opens the Choose A Data Source Type window, shown in Figure 8-11.

There are different ways to connect to a data source, including directly to the database, via a Web service, via an object, or through SharePoint. This book shows you how to use LINQ to SQL, which is connected by selecting Object and clicking Next, which shows the Select The Data Objects window in Figure 8-12.

Page 258
Image 258
Microsoft 9GD00001 manual Setting Up a Data Source, 235