Thought Sharing

Tuesday, November 23, 2010

Database connectivity using RDO (Remote data Object)

Database connectivity using RDO (Remote data Object)

RDO uses ODBC (Open Data Base Connectivity), an ODBC Data Source, which must be set up through the Windows Control Panel. 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").The following steps is used to setup system DSN as:
1.) Go to Start -> Windows Control Panel; double-click on Administrative Tools, then Data Sources (ODBC). The ODBC Data Source Administrator screen is displayed. Click on the System DSN tab.
2.) 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.
3.) 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.
4.) 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.
5.) When you are returned to the ODBC Microsoft Access Setup screen, the database you selected should be reflected as shown below. Click OK to close this screen.
6.) When you are returned to the ODBC Data Source Administrator screen, the new DSN should appear as shown below. Click OK to close this screen.
Connecting VB application to MS Access database using the RDO Data Control (RDODC):
1.) Start a new VB project, and from the Components dialog box (invoked from the Project -> Components menu), select Microsoft Remote Data Control 6.0 (SP3) as shown below and click OK.
2.) Drag & Drop a remote data control (RDC) on your form, and set the properties as follows
DataSourceName: Select the DSN name as created above. Eg. Biblio
SQL: select * from Customers
3.) Now put text boxe on the form, and set DataSource, and DataField properties as follows:
DataSource: MSRDC1
DataField: CustomerName
Repeat this step for all other textboxes on the form.
4.) Save and run the program. It works just like the other data control.
Code for Add, delete, edit, update, movefirst, movenext, first, last operations on the click event of command button:
Private Sub Command1_Click()
MSRDC1.Resultset.AddNew
End Sub
======================
Private Sub Command2_Click()
MSRDC1.Resultset.Delete
End Sub
=====================
Private Sub Command3_Click()
MSRDC1.Resultset.MoveFirst
End Sub
======================
Private Sub Command4_Click()
MSRDC1.Resultset.Update
End Sub
======================
Private Sub Command5_Click()
MSRDC1.Resultset.Edit
End Sub
======================
Private Sub Command6_Click()
MSRDC1.Resultset.MovePrevious
End Sub
======================
Private Sub Command7_Click()
MSRDC1.Resultset.MoveFirst
End Sub
======================
Private Sub Command8_Click()
MSRDC1.Resultset.MoveLast
End Sub