21.2. Binding

The most common type of application is one that retrieves data from a database, displays the data, allows changes to be made, and then persists those changes back to the database. The middle steps that connect the in-memory data with the visual elements are what is referred to as DataBinding. DataBinding often becomes the bane a of developer's existence because it has been difficult to get right. Most developers at some stage or another have resorted to writing their own wrappers to ensure that data is correctly bound to the controls on the screen. Visual Studio 2008 dramatically reduces the pain of getting two-way DataBinding to work. The examples used in the following sections work with the AdventureWorks Lite sample database, and you saw earlier in this chapter that you will need to add this as a data source to your application. For simplicity, you'll work with a single Windows application, but the concepts discussed here can be extended over multiple tiers.

In this example, you build an application to assist you in managing the customers for AdventureWorks. To begin, you need to ensure that the AdventureWorksDataSet contains the Customer, SalesTerritory, Individual, Contact, and SalesOrderHeader tables. (You can reuse the AdventureWorksDataSet from earlier by clicking the "Configure Dataset with Wizard" icon in the Data Source window and editing which tables are included in the DataSet.) With the form designer (any empty form in your project will do) and Data ...

Get Professional Visual Studio® 2008 now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.