Retrieving a Set of Records

Visual J++ provides the DataSource control to access data in the 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 Designer, however, only supports the DataSource component. For information about programming with the ADO components, see the ADO Tutorial (VJ++).

The following steps show how to use the DataSource control in the Designer. (You must have already added this control to the Toolbox.)

To retrieve data with the DataSource control

  1. Add a DataSource control to your form. (For information about adding controls to a form, see Adding Controls to a Form.)

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

  2. To connect to the database, you set the connectionString property of the DataSource control. (For information about setting properties, see Setting Properties with the Properties Window.)
  3. To query the database, set the queryString property of the DataSource control to an SQL string. For example, to retrieve all records from a table called Products, enter Select * from Products.

Now that you have retrieved a set of records, you must bind the data to display it on the form.