ADO defines the DataBinder component to perform simple data binding. This component creates and manages the bindings between the fields in a recordset and the bindable properties of WFC components. For more information about whether a property can be bound, see Bindable Properties.
Although a single DataBinder component can manage multiple bindings, it is associated with only one recordset. To bind the fields of a second recordset, you must use another DataBinder component. Additionally, a DataBinder component can only bind to components that exist on the same design surface as itself; for example, a DataBinder component cannot bind to a component that exists on a different form.
If the component of a bound property supports a change notification for that property, the field in the recordset is automatically updated when the property changes. Note that the DataBinder component provides no mechanism for validating the change made to the propertyÆs value. For more information, see Property Change Requests and Notifications.
The following example shows how to programmatically perform simple data binding with the DataBinder component. Note that the DataBinder component uses an array of DataBinding objects to manage the bindings.
import wfc.data.*;
import wfc.data.ui.*;
import wfc.ui.*;
/* Use the Connection and Recordset components to
connect to a database and retrieve a recordset. */
Connection c = new Connection();
c.setConnectionString(ôdsn=myDSN;uid=myUID;pwd=myPWDö);
c.open();
Recordset rs = new Recordset();
rs.setActiveConnection(c);
rs.setSource(ôselect * from authorsö);
rs.open();
/* Create a DataBinder component. To associate this
component with rs, set the dataSource property. */
DataBinder db = new DataBinder();
db.setDataSource(rs);
/* Create the components whose properties will be bound. */
Edit edit1 = new Edit();
Edit edit2 = new Edit();
/* Set the DataBinder componentÆs bindings property to
an array of DataBinding objects. This array defines
the bindings between the text property of each Edit
component and the fields in the recordset. */
db.setBindings(new DataBinding[] {
new DataBinding(edit1, ôtextö, ôfirstNameö),
new DataBinding(edit2, ôtextö, ôlastNameö) } );
}
For more information about the DataBinder componentÆs dataSource property, see Complex Data Binding. For information about using the DataBinder component in the Designer, see Accessing Data.