Using the Oracle Data Control with Visual Basic

To use the Oracle Data Control with Visual Basic 5.0, perform the following steps:

  1. Start Visual Basic and create a new project and then use the Components option of the Project menu to add "Oracle Data Control" to the project.

    projcomp.gif

The Oracle Data Control will be added to your Visual Basic tool palette and will look like this:

oradc.gif

The Oracle Data Control makes creating a dynaset easier, because it does not require you to create the underlying objects. When the Oracle Data Control is refreshed, a client (if needed), session, database, and dynaset are created automatically.

2. To add the Oracle Data Control to a project, simply drag and drop the control on a form. Resize and position the control.

3. Set up the Connect, DatabaseName, and RecordSource properties to access the Oracle database. Change the name of the control to ORADataControl.

dcprops.gif

4. When the Oracle Data Control is set up, you can access the data in a Visual Basic control, such as a TextBox control, that you drag and drop on a form. Simply set the Data properties to access the data field and source that you want.

boxprops.gif

5. When the project is run, the data identified by the RecordSource property is displayed and can be navigated with the Oracle Data Control.

runform.gif

You can also access the Oracle data in the Microsoft FlexGrid Control to get a convenient display of all the data in the table. The grid control is added with the Components option of the Project menu.

Setting Oracle Data Control Properties Programmatically

The following code fragment demonstrates how to programmatically set the properties of the Oracle Data Control required to create a dynaset. These are the same properties that you can set with the Properties window of Visual Basic.

  1. Create a new project and then use the Components option of the Project menu to add "Oracle Data Control" to the project.

  2. Drag and drop an Oracle Data Control on a form. Change the name of the control to 'ORADataControl'.

  3. After you have inserted an Oracle Data Control on a form, the following code can be added to the Load procedure associated with the form.

...

'Set the username and password.

ORADataControl.Connect = "scott/tiger"

'Set the database name.

ORADataControl.DatabaseName = "ExampleDb"

'Set the record source.

ORADataControl.RecordSource = "select * from emp"

'Refresh the data control.

ORADataControl.Refresh

...

You now have a valid client, session, database, and dynaset. The client, session, database, and dynaset are referenced using oradatacontrol.database.session.client, oracontrol.database.session, oradatacontrol.database, and oradatacontrol.recordset, respectively.

4. You can access the data in the RecordSource using Visual Basic controls, such as a TextBox. For example, after you insert a TextBox on the form, you can set the DataSource property to ORADataControl and the DataField property to EMPNO. When the project is run, the DataSource and DataField properties will point to the data objects that you have specified.

Contents