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
-
In Project Explorer, double-click the name of your form to open it in the Forms Designer.
-
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.
-
To connect to the database, set the connectionString property of the DataSource control:
-
Select the DataSource control on the form.
-
In the Properties window, click the connectionString property, and then click the ellipses (...) button to open the Data Link Properties dialog box.
-
To access a named ODBC data source:
-
Click the Provider tab and select Microsoft OLE DB Provider for ODBC Drivers.
-
Click the Connection tab. In step 1, select Use data source name and select your data source in the drop-down list. In step 2, you can enter the user name and password, if needed.
-or-
To access a Microsoft Access .mdb file directly without using ODBC:
-
Click the Provider tab and select Microsoft Jet 3.51 OLE DB Provider.
-
Click the Connection tab. In step 1, enter the full path and file name of your database, or click the ellipses (...) button to browse for the file. In step 2, you can enter the user name and password, if applicable.
-
Click OK to establish the database connection.
-
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.
-
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.