HOWTO: ADC: How To Use From Inside a Visual Basic Program

Last reviewed: September 30, 1997
Article ID: Q165297
The information in this article applies to:
  • Microsoft Internet Information Server version 3.0 on the following platform: Windows NT

SUMMARY

The Microsoft Advanced Data Connector (ADC) can be used inside a Visual Basic program as easily as it can be used from inside Internet Explorer (IE) 3.0. You are not able to bind controls to it with the AdvancedDataControl as you can in IE, but you can use the AdvancedDataSpace and the AdvancedDataFactory objects to return a recordset to your Visual Basic program with a small amount of code. With this returned recordset you can populate non-bound controls as you would in a normal program.

Since the ADC only allows native update capability with the Microsoft SQL Server ODBC driver, you can use the information in this article to update non-SQL server ODBC databases very easily.

MORE INFORMATION

Sample Program

This example uses the ADC CreateObject method of the AdvancedDataSpace on the client to instantiate the AdvancedDataFactory object on a remote server over http. The AdvancedDataFactory 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 install the ADC client components by using a CODEBASE parameter in an OBJECT tag of an HTML page. To do this go to the sample page on your ADC Server at http://[SERVER]/Msadc/Samples/Adctest.asp and these components are 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:

          Dim rs As Object    'Resultset
          Dim ads As Object   'AdvancedDataSpace
          Dim adf As Object   'AdvancedDataFactory
    
          Private Sub Form_Load()
            Set ads = CreateObject("AdvancedDataSpace")
            Set adf = ads.CreateObject("AdvancedDataFactory", _
             "http://www.myserver.com")
          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 = adf.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%'"
            adf.Query strCn, strSQL
          End Sub
    
    
NOTE: You will need to change the DSN to match a System DSN on your IIS/ASP/ADC server before continuing.

  1. Start the program or press the F5 key.

  2. Click the Command1 button to execute the ADC code that returns a resultset. If it executes successfully, row 1 column 1 will be output to the Debug 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

Web site for ADC, http://www.microsoft.com/adc ADC public newsgroup, microsoft.public.adc Readme file, file://\\[SERVER DIR]\msadc\Doc\readme.txt ADC Help, file://\\[SERVER DIR]\msadc\Doc\madc10.hlp

Keywords          : kbprg iisapi kbhowto
Version           : 3.0
Platform          : NT WINDOWS
Issue type        : kbhowto


================================================================================


THE INFORMATION PROVIDED IN THE MICROSOFT KNOWLEDGE BASE IS PROVIDED "AS IS" WITHOUT WARRANTY OF ANY KIND. MICROSOFT DISCLAIMS ALL WARRANTIES, EITHER EXPRESS OR IMPLIED, INCLUDING THE WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. IN NO EVENT SHALL MICROSOFT CORPORATION OR ITS SUPPLIERS BE LIABLE FOR ANY DAMAGES WHATSOEVER INCLUDING DIRECT, INDIRECT, INCIDENTAL, CONSEQUENTIAL, LOSS OF BUSINESS PROFITS OR SPECIAL DAMAGES, EVEN IF MICROSOFT CORPORATION OR ITS SUPPLIERS HAVE BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES. SOME STATES DO NOT ALLOW THE EXCLUSION OR LIMITATION OF LIABILITY FOR CONSEQUENTIAL OR INCIDENTAL DAMAGES SO THE FOREGOING LIMITATION MAY NOT APPLY.

Last reviewed: September 30, 1997
© 1998 Microsoft Corporation. All rights reserved. Terms of Use.