Implementing ADO with Various Development Languages

The ADO Rosetta Stone

Don Willits
Microsoft Data Access Group

July 1998

Part One: Getting Started with ADO

Part Two: ADO and COM

Part Three: Advanced Discussion and Related Information

Click to copy the sample files associated with this technical article.

Summary: Describes how to implement ADO in Microsoft Visual Basic for Applications, Visual C++, VBScript, JScript, and Java. (56 printed pages) Covers:

Introduction

Microsoft® ActiveX® Data Objects (ADO) is a language-neutral object model that is the keystone of Microsoft's Universal Data Access (UDA) strategy. Because it is language neutral and accommodates a variety of development languages, it is difficult to present the practical usage for each environment. This article is a discussion of the complexities inherent to using ADO within various languages and implementation mechanisms within those languages.

To facilitate this discussion of ADO, take a lesson from the Rosetta Stone, a slab of black basalt that provided scholars with their first significant key to deciphering ancient Egyptian hieroglyphics. The Rosetta Stone was discovered in 1799 and appeared to contain one message (a group of priests praising their rulers for eliminating overdue taxes in the year 196 B.C.) in three languages: Greek, demotic characters, and Egyptian hieroglyphics. Because scholars knew Greek, they enthusiastically attempted to use the Rosetta Stone to decipher the hieroglyphics. Twenty years later, French scholar Jean Champollion produced a dictionary of Egyptian hieroglyphics after rigorous comparison of the hieroglyphics to the Greek.

In the spirit of Champollion's accomplishment, the following pages describe how to implement ADO applications using Microsoft Visual Basic® for Applications (VBA), Microsoft Visual C++®, Java, Microsoft Visual Basic, Scripting Edition (VBScript), and Microsoft JScript. In this case, VBA is the "Greek text"; you can use it as the base from which to learn about the other languages.

Numerous code listings are included in the text, as well as two sets of code examples in an accompanying zip file. The first set contains all the code listings presented in this document within working projects built with Microsoft Visual Studio™ 97 and the Microsoft Data Access version 2.0 software development kit (SDK), which includes ADO 2.0. In each of these examples, you will find files named "LISTING," which contain the actual code samples. The second set, the Rosetta Stone samples, implement several common ADO scenarios and are ported to a variety of development languages and environments.

The article was written against ADO 1.5 and ADO 2.0 using Visual Studio 97. Updates will be provided, as appropriate, for new features introduced with subsequent releases of either product. The latest version of this article is available at www.microsoft.com/data.

This article does not discuss the ADO object model or its objects, methods, properties, or syntax. If you are not already familiar with ADO, refer to the ADO documentation for more information.

COM as the Heart of ADO Development

Microsoft's Component Object Model (COM) is central to all ADO development. When you use ADO, you use COM, regardless of the language you have chosen for the application. In particular, ADO is an Automation server, and you use COM to invoke and utilize ADO objects.

Some languages hide the implementation details of COM more than others do, so you don't need more than a beginner's understanding of COM to proceed. However, as your expertise with COM grows, so does your ability to use ADO efficiently and with more complexity. Microsoft Visual Basic for Applications (VBA) hides many of the details of COM development, so you might choose VBA for your ADO applications. Visual C++, Java, and Web-based scripting do not provide as much native COM support, but they do offer you more low-level control than what you might find with VBA.

The following are key areas of COM that you might want to be familiar with. In addition to understanding foundational COM concepts, these subjects directly affect your ability to develop an ADO application:

For more information about these topics, see parts two and three.

For developers new to both COM and ADO, it may seem like a double learning curve to get started with ADO. This is true, but once you master the COM fundamentals needed for ADO, you are ready to implement applications utilizing other COM components. As you are learning ADO techniques, try them first in VBA, and then try them in Visual C++ or Java. This will help you determine whether any difficulties you encounter are in your understanding of COM or ADO.