The NWProducts Application

Team Fly 

Page 506

edited, the new value replaces the column's value in the DataSet. A data-bound control is in effect a window for viewing and editing a specific column in the DataTable.

In most cases we bind the control's Text property, but there are other properties you can bind to a data source, such as the Tag property. To set the data-bound properties of a control, expand its Data-Bindings section in the Property Browser, select one of the data-bound properties, and set it to the appropriate column name. You will notice that the properties listed in the DataBindings section do not have unique names; you will see a Text property, a Tag property, and so on. In the DataBindings section, you bind the values of these properties to a data field. The properties by the same name that appear outside the DataBindings section can be set to static values as usual.

Some of the Windows controls can be bound to columns and display all the rows in the table. The ListBox and ComboBox controls, for example, can be populated with the rows of a table and display a specific column. These controls are used almost exclusively as lookup tools on data entry forms, and you'll see several examples of this technique in the following sections. It's possible to populate a ComboBox control with the rows of the Categories table, for example and bind the control to the CategoryID field of the Products table. As a result, every time you move to another row in the Products table, the current product's category name will appear on the control. To change the category of the current row, you simply select another category name on the control.

Data-binding is not new to ADO.NET.Data-binding was available with earlier versions of ADO, but it has never been a real developer's tool. You will see how to use data-binding to build a functional viewing and editing interface for the Products table, but most of the examples aren't based on data-binding. We'll discuss the relevant topics as we go through the examples.

The NWProducts Application

Our first example is a typical application for viewing and editing a table with products. You've seen how to display the Northwind Products table's rows on a DataGrid control and how to submit to the database the changes made to these rows by the user with the DataAdapter object. In this chapter we're going to build a functional and intuitive interface for viewing and editing the rows of the Products table.

The basic requirement of this application is that we shouldn't have to download the entire table to the client: in a production database the Products table is quite large. This application will be used by multiple users on a local area network, and they should be able to see each other's changes. If we give each user a copy of the table, multiple users may edit the same line. Moreover, there will be a lot of conflicts we'd have to reconcile as we submit the changes to the database. We'll build a connected application that submits the changes to the database as soon as they occur.

Another important aspect of the application is the navigational model. Even if the rows of the Products table are copied to a DataSet at the client, we should provide a mechanism for users to locate a desired product quickly and conveniently. Dumping all the product names on a ListBox control may work with a small table, but it's a totally impractical approach for a production database with many thousands of products. Moreover, we'll allow users to locate a product with several criteria, and not just the product's name. We'll allow users to select a product by its name, its category, or its supplier, on a separate form.

The Products table is related to the Categories and Suppliers tables. Obviously, we can't display category and supplier IDs on our interface; we must retrieve and display each product's category and

Team Fly 


Visual Basic  .NET Power Tools
Visual Basic .NET Power Tools
ISBN: 0782142427
EAN: 2147483647
Year: 2003
Pages: 178

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net