How to Set VB Data Control to External ODBC Database Dynaset

Last reviewed: June 21, 1995
Article ID: Q109800
The information in this article applies to:

- Standard and Professional Editions of Microsoft Visual Basic for

  Windows, version 3.0

SUMMARY

The following sample code fragment sets a data control (Data1) to a Dynaset based upon an external ODBC database:

   ' Set DatabaseName property to a valid Data Source Name (DSN) that is
   ' registered in the ODBC.INI file in your Windows directory:
   Data1.DatabaseName = "datasourcename"
   Data1.Connect = "odbc;uid=user;pwd=password;database=pubs"
   Data1.RecordSource = "tablename"
   ' Or you can set the Data1.RecordSource property to an SQL query:
   ' Data1.RecordSource = "select * from tablename where ..."
   Data1.Refresh   ' Must update the data control with new Dynaset.

NOTE: You cannot set a data control directly to a Dynaset variable, but you can set a Dynaset variable to the data control's recordset:

   Dim ds as Dynaset
   ...
   Set Data1.Recordset = ds   'This statement is not supported.
   Set ds = Data1.Recordset   'This statement is supported.

A data control requires additional information that is not available in a Dynaset object.

MORE INFORMATION

Before you can edit an external ODBC table, the table must contain a unique index. If you get the following error message, you might not have a unique index on the table:

   Can't perform operation; it is illegal.

You could also receive this error if the Data1.Recordset.Updatable flag is not set to True. Also, if you set the Data1.Options property to 64 (SQL_PASSTHROUGH), the data control will not be updatable.

REFERENCES

  • "Microsoft Visual Basic for Windows Professional Features Book 2:

        Data Access Guide," pages 14-15 and Appendix C.
    


Additional reference words: 3.00
KBCategory: kbinterop kbprg
KBSubcategory: APrgDataODBC


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: June 21, 1995
© 1998 Microsoft Corporation. All rights reserved. Terms of Use.