Time Out to Discuss Data Binding

Since we are going to be discussing binding fields of ActiveX controls to ADO recordsets, now is probably a good time to discuss data binding. Data binding is one of the more powerful uses of ActiveX controls. Essentially, using data binding allows a property of the ActiveX control to bind with a specific field in a database.

When the bound control property (such as the text box's

Text
property) is modified by the user of our control, the control actually notifies the database that the value has changed. It then requests that the relevant field of the current record be updated. This process takes place, and in return the database notifies the control of the success or failure of the update. Hmmm…sounds like a data control to me.

So in a nutshell, data binding allows a database entry, such as a record field, to be linked to a property of an ActiveX control.

Our ActiveX control is typically hosted in a VB 6.0 form. This form and the bound controls provide the visual interface to the current record. The figure below illustrates a conceptual view of this binding:

In this example, the ActiveX control has two text boxes, each of which has bound its

Text
property to the fields of a record. When the user makes changes to either text box, the modifications are made to the control's
Text 
property. These changes are communicated to the database.

Remember earlier on when we mentioned than an ActiveX control is 'hosted' by a form? An ActiveX control needs a form to live on. Data binding is a notification mechanism that links our ActiveX control's properties - through the container (i.e. our form) to a data source (i.e. a database field).

When we bind an ActiveX control property, we must make sure that the control is able to send notifications to the database whenever the property changes. That notification is sent to the control container (i.e. the hosting VB form), which processes it and returns the database's response to the control.

In order to see the brand-new features that VB 6.0 offers database programmers, we are going to create three projects in this chapter:

VB 6.0 has really provided database programmers with a wealth of possibilities. Let's take a look.

© 1998 by Wrox Press. All rights reserved.