Share via


Visual Basic Concepts

Using the RemoteData Control

The RemoteData control is similar to the Visual Basic Data control in most respects. Both the Data control and the RemoteData control are designed to connect data-aware bound controls to a data source. The primary difference is that the RemoteData control uses RDO to connect to the ODBC driver manager, while the Data control uses DAO to connect to the Jet database engine, which can connect to native Jet databases or IISAM data sources. The Data control can also connect indirectly to RDO by using the ODBCDirect interface. Even though both controls use the same ODBC driver manager and data source entries, RDO, ODBCDirect, and DAO cannot share data source connections, data objects, or other resources.

Note   The Data control supports the ability to use the RDO DLLs via the ODBCDirect option. In this case, your code uses Data Access Objects (DAO) instead of RDO to manage the Data control and its result sets.

Without a RemoteData control, a Data control, or its equivalent, data-aware (bound) controls can’t automatically access data. You can perform many simple remote data access operations using the RemoteData control without writing any code at all. However, most applications rely on additional RDO code to perform most data access operations, as RDO provides more flexibility and additional options not exposed by the RemoteData Control alone. In most respects, the RemoteData Control behaves very much like the Data control.

Data-aware controls bound to a RemoteData control automatically display data from one or more columns for the current row or, in some cases, for a set of rows on either side of the current row. The RemoteData control performs all operations on the current row.

If the RemoteData control is instructed to move to a different row, all bound controls automatically pass any changes to the RemoteData control to be saved by the ODBC data source. The RemoteData control then moves to the requested row and passes data back from the current row to the bound controls, where it is displayed.

Handling Errors with the RemoteData Control

The RemoteData control automatically handles a number of contingencies, including empty result sets, adding new rows, editing and updating existing rows, and handling some types of errors. However, in more sophisticated applications, you will need to trap some error conditions that the RemoteData control can’t handle. For example, if the remote server has a problem accessing the data source, doesn’t have permission, or can’t execute the query as coded, a trappable error results. If the error occurs before your application procedures start, or because of some internal errors, the RemoteData control's Error event is triggered.

The RemoteData control uses and creates the same RDO objects discussed in this chapter. When the appropriate RemoteData control properties are set, the RemoteData control can create an rdoResultset that can be manipulated in code like any other rdoResultset. You can also create an rdoResultset in code and set the RemoteData control’s Resultset property to point to this object.

Note   To use the RemoteData control, you need to add it to the Visual Basic Toolbox. To add the RemoteData control to your Toolbox, click the Project menu, then click Components; in the Components dialog box, click the Controls tab and select the “Microsoft RemoteData Control 2.0” check box.

RDO is only supported on 32-bit operating systems (Windows 95, Windows 98, and Windows NT). To use the Remote Data Objects, you must set a reference to the Microsoft Remote Data Object 2.0 object library in the Visual Basic References dialog.

Getting the Resultset from a Remote Data Control

When you assign a resultset to a RemoteData Control (RDC), any controls bound to it are not automatically updated. If, for example, you bind a control to the resultset of an RDC, the resultset doesn't automatically display in the control. To illustrate this:

  1. Start Visual Basic and open a Standard EXE project.

  2. Reference the RDC.

  3. Place an RDC on the form.

  4. Place a TextBox control on the form.

  5. Set the following TextBox properties:

    DataSource: MSRDC1

    DataField: au_lname

  6. Place a CommandButton control on the form and add the following code to its Click event (substitute an actual DSN for the one used below):

    Dim cn As New rdoConnection
    cn.Connect = _
      "dsn=pinkpearl;database=rdobugs;uid=rdo;pwd="
    cn.EstablishConnection
    Set MSRDC1.Resultset = cn.OpenResultset("select * from [authors]")
    
  7. Run the project (F5).

  8. Click the CommandButton.

Notice that the bound control does not populate with data as you would expect. You must issue the command MSRDC1.Refresh for the bound control to populate, which causes the server to send the entire resultset again. (Note that this can take a long time in some situations.)

To work around this problem, set any bound control's datafield after setting the resultset in code. For example, do it after the following line:

Set MSRDC1.Resultset = cn.OpenResultset("select * from [authors]")