Retrieving a Set of Records

See Also

Visual J++ provides the DataSource control to access data in the Forms Designer. This control allows you to connect to and query a database to retrieve a set of records.

Note   To retrieve a recordset in code, you can also use the Connection, Command, and Recordset components. The Forms Designer, however, supports only the DataSource component. For information about programming with the ADO components, see the ADO Tutorial (VJ++).

To retrieve data with the DataSource control

  1. In Project Explorer, double-click the name of your form to open it in the Forms Designer.

  2. In the Toolbox, click the WFC Controls tab. Click the DataSource control in the Toolbox, and then click your form to add the control.

    Note   Because the DataSource control only retrieves data and does not display it, the control is not visible when you run your form.

  3. To connect to the database, set the connectionString property of the DataSource control:
  4. To access a named ODBC data source:

    -or-

    To access a Microsoft Access .mdb file directly without using ODBC:

  5. Click OK to establish the database connection.

  6. To query the database, set the commandText property of the DataSource control to an SQL string. For example, to retrieve all records from a table called Products, enter Select * from Products.

  7. To make the recordset updateable, set the lockType property to Optimistic.

Now that you have retrieved a recordset, you must bind it with the DataBinder control or the DataGrid control.