HOWTO: Use RDS From Inside a Visual Basic Program

ID: Q165297


The information in this article applies to:


SUMMARY

Microsoft Remote Data Service (RDS) can be used inside a Visual Basic program as easily as it can be used from inside Microsoft Internet Explorer. You are not able to bind controls to it with the RDS.DataControl as you can in Internet Explorer, but you can use the RDS.DataSpace and the RDSServer.DataFactory objects to return a recordset to your Visual Basic program with a small amount of code. With the returned recordset you can populate unbound controls.


MORE INFORMATION

Sample Program

This example uses the CreateObject method of the RDS.DataSpace on the client to instantiate the RDSServer.DataFactory object on a remote server over HTTP. The RDSServer.DataFactory object then uses the Query method to execute SQL on the remote server and return an ADO/R recordset to the client.

In order to run the example code you first need to make sure the RDS Server components have been installed on the Internet Information Server (IIS) computer. These can be obtained from the Microsoft Universal Data Access web page located at the following URL:
http://www.microsoft.com/data/
The client components must also be installed on the client computers. If the client computer has Internet Explorer 4.01 or greater installed, the RDS 1.5 client components are included. For clients running Internet Explorer 3.0, the client components must be downloaded to the clients computer. One way of doing this is by using a CODEBASE parameter in the OBJECT tag of an HTML page. To do this go to the sample page on your RDS Server located at:
http://[SERVER]/Msadc/Samples11/Adctest.asp
The components will automatically be installed on the client.

This sample uses SQL Server and the Pubs database, but you can change the System DSN, UID, PWD, and SQL to match any ODBC database you may be using.
  1. Start a new project in Visual Basic and choose "Standard EXE." Form1 is created by default.


  2. Add two Command buttons, Command1 and Command2, to Form1.


  3. Paste the following code into the General Declarations section of Form1:


  4. 
       Dim rs As Object   'Resultset
       Dim ds As Object   'RDS.DataSpace
       Dim df As Object   'RDSServer.DataFactory
    
       Private Sub Form_Load()
       Set ds = CreateObject("RDS.DataSpace")
       Set df = ds.CreateObject("RDSServer.DataFactory", _
       "<LINK TYPE="GENERIC" VALUE="http://myserver")">http://myserver")</LINK>
       End Sub
    
       Private Sub Command1_Click()
       'This query returns a recordset over HTTP.
       Dim strCn As Variant, strSQL As Variant
       strCn = "dsn=pubs;uid=sa;pwd="
       strSQL = "select * from authors"
       Set rs = df.Query(strCn, strSQL)
       Debug.Print rs(0)     'Print Row 1, Col 1 to Debug window
       End Sub
    
       Private Sub Command2_Click()
       'This example executes an action query but does not return
       'a recordset.
       Dim strCn As Variant, strSQL As Variant
       strCn = "dsn=pubs;uid=sa;pwd="
       strSQL = "Update authors Set au_fname = 'Jon' Where au_lname" _
       & " Like 's%'"
       df.Query strCn, strSQL
       End Sub
      
NOTE: You will need to change the DSN to match a System DSN on your IIS/ASP/RDS server before continuing.
  1. Start the program or press the F5 key.


  2. Click the Command1 button to execute the RDS code that returns a resultset. If it executes successfully, row 1, column 1 will be outputto the Debug Immediate window.


  3. Click the Command2 button to execute the action query that updates the au_fname column in the authors table. No data will be returned from the action query.



REFERENCES

For additional information, please see the following World Wide Web URL:

http://www.microsoft.com/data/rds/
Remote Data Service public newsgroup:
microsoft.public.ado.rds

Additional query words: ADC


Keywords          : kbprg kbRDS150 kbRDS200 kbVBp500 kbVBp600 kbGrpVBDB kbDSupport 
Version           : WINDOWS:1.5
Platform          : WINDOWS 
Issue type        : kbhowto 

Last Reviewed: July 15, 1999