Vous êtes sur la page 1sur 8

VB PRACTICAL FILE

[Type text]

RDO (Remote Data Objects)

Follow the steps below to set up an ODBC Data Source (this process is also called "setting up
a DSN", where "DSN" stands for "Data Source Name"). These steps assume Windows 2000
for the operating system. On other versions of Windows, some steps may vary slightly.
Via Windows Control Panel, double-click on Administrative Tools, then Data
Sources (ODBC). The ODBC Data Source Administrator screen is displayed, as shown
below. Click on the System DSN tab.







VB PRACTICAL FILE
[Type text]

Click the Add button. The Create New Data Source dialog box will appear. Select
Microsoft Access Driver (*.mdb) from the list and click the Finish button.

The ODBC Microsoft Access Setup dialog box will appear. For Data Source Name,
type Biblio. If desired, you can type an entry for Description, but this is not required.


VB PRACTICAL FILE
[Type text]

Click the Select button. The Select Database dialog box appears. On a default
installation of VB6 or Visual Studio 6, the BIBLIO.MDB sample database should reside in
the folder C:\Program Files\Microsoft Visual Studio\VB98. Navigate to that folder, select
BIBLIO.MDB from the file list, and click OK.

Note: If VB was installed in a different location on your system, navigate to the appropriate
folder. If you do not have the BIBLIO.MDB sample database file on your system at all,
you can download it here. In that case, copy the file to the folder of your choice, and
navigate to that folder to select the database for this step.
When you are returned to the ODBC Microsoft Access Setup screen, the database you
selected should be reflected as shown below. Click OK to dismiss this screen.


VB PRACTICAL FILE
[Type text]

When you are returned to the ODBC Data Source Administrator screen, the new DSN
should appear as shown below. Click OK to dismiss this screen.


At this point, the Biblio database is ready to be used with RDO in the sample application.









VB PRACTICAL FILE
[Type text]

Application 1: Using the RDO Data Control (RDODC)
To build the first sample application, follow the steps below.

Start a new VB project, and from the Components dialog box (invoked from the
Project -> Components menu), select Microsoft RemoteData Control 6.0 (SP3) as shown
below and click OK.








VB PRACTICAL FILE
[Type text]

The RDO Data Control should appear in your toolbox as shown below:


Put a remote data control (RDC) on your form, and set the properties as follows:
Property Value
Name rdoBiblio
DataSourceName Biblio
SQL select * from authors
Now put three text boxes on the form, and set their Name, DataSource, and DataField
properties as follows:
Name DataSource DataField
txtAuthor rdoBiblio Author
txtAuID rdoBiblio Au_ID
txtYearBorn rdoBiblio Year Born
Save and run the program. Notice how it works just like the other data control.

VB PRACTICAL FILE
[Type text]

Now change the SQL property of the data control to select * from authors order by
author and run the program again. Notice the difference.

Change the SQL property back to what it was and add three command buttons to the
form, and set their Name and Caption properties as follows:

Name Caption
cmdNameOrder Order by Name
cmdYearOrder Order by Year
cmdIDOrder Order by ID
Put the following code in the cmdNameOrder_Click event:
rdoBiblio.SQL = "select * from authors order by author"
rdoBiblio.Refresh
Put the following code in the cmdYearOrder_Click event:
rdoBiblio.SQL = "select * from authors order by [year born]"
rdoBiblio.Refresh
Put the following code in the cmdIDOrder_Click event:
rdoBiblio.SQL = "select * from authors order by au_id"
rdoBiblio.Refresh

Save and run the program and see what happens when you click the buttons.





VB PRACTICAL FILE
[Type text]

A screen-shot of the sample app at run-time is shown below:

Vous aimerez peut-être aussi