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, the DataBinder component should be used only bind to components that exist on the same form.
If the component of a bound property supports a change notification for that property, the DataBinder component marks the binding as dirty when the property value changes. The recordset is updated when the user navigates to a new record or when the DataBinder.commitChanges method is called in code. For more information, see Property Change 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 com.ms.wfc.data.*;
import com.ms.wfc.data.ui.*;
import com.ms.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 Forms Designer, see Accessing Data.