Complex Data Binding

Complex data binding refers to components that interact directly with a recordset. A complex data-bound component provides dataSource and dataMember properties that identify the recordset it is bound to. Note that the properties of complex bound components can still be simple bound via the DataBinder component.

dataSource and dataMember Properties

The dataSource property identifies an object that implements the IDataSource interface. This object exposes one or more recordsets. The dataMember property then specifies the name of the recordset that is currently bound to the component. For example:

/* Bind the component to the recordset named "Products",
   which is exposed by the data source, ds. */
dbComponent.setDataSource(ds);
dbComponent.setDataMember("Products"); 

If you do not set the dataMember property, then the data source’s default recordset will be bound. (You can explicitly specify the default recordset by setting the dataMember property to null.)

/* Bind the component to the default recordset
   exposed by the data source, ds. */
dbComponent.setDataSource(ds);
dbComponent.setDataMember(null);  /* This line is optional. */

Note that the Recordset and DataSource components already implement the IDataSource interface. Therefore, you can set the dataSource property directly to one of these components. In this case, you do not have to set the dataMember property:

/* Set the dataSource property directly to the Recordset
   component,rs, without setting the dataMember property. */
dbComponent.setDataSource(rs);

Complex Bound Components in Visual J++

Visual J++ provides the following complex data-bound components:

Component Description
DataBinder Binds a field from a recordset to the property of a WFC component. (Although the DataBinder component is used to perform simple binding, the component itself exposes dataSource and dataMember properties.)
DataGrid Binds multiple fields from a recordset and displays the data in a grid format.
DataNavigator Allows the user to change the current record in a recordset. Any other component that is bound to the same recordset is then updated to reflect the new current row.

For information about using these components in the Forms Designer, see Accessing Data.