Home arrow C++ arrow Page 2 - ActiveX Data Objects (ADO) In Visual C++
C++

ActiveX Data Objects (ADO) In Visual C++


If you've ever wondered how to connect to a database using ADO in Microsoft Visual C++ then look no further. In this excellent step-by-step guide, Neville shows us how to do just that...

Author Info:
By: Neville Mehta
Rating: 5 stars5 stars5 stars5 stars5 stars / 46
October 27, 2002
TABLE OF CONTENTS:
  1. · ActiveX Data Objects (ADO) In Visual C++
  2. · The Myriad of Data Access Technologies
  3. · An ADO Application in VC
  4. · Writing the Function
  5. · Conclusion

print this article
SEARCH DEVARTICLES

ActiveX Data Objects (ADO) In Visual C++ - The Myriad of Data Access Technologies
(Page 2 of 5 )

Today's applications are incomplete without an aptly developed backend. As a matter of fact, the presence of a database in an organization isn't something that's optional anymore Ė it's mandatory.

Applications are created to interact with data sources. When I say data source, I could mean excel sheets, indexed sequential data files, text files etc. Applications use different data access techniques to extract data from data sources. These techniques should be easy to use, and there mustn't be complex deployment issues associated with them. They should perform well in terms of using the smallest amount of processing power.

These issues led to the development of Universal Data Access (UDA) by Microsoft. UDA was based on COM and aimed to provide high performance data access to various data sources.

Even today, we have various data access technologies available. Some of them are:
  • ODBC (Open Database Connectivity): ODBC is a set of programming APIís, which allows you to connect to a variety of data sources. Prior to ODBC we used to have DB-Libraries. The one flaw with DB-Libraries was that they were optimized to access data from a specific source, which made the application very dependent on the database used. On the other hand, ODBC could interact with various data sources using a common set of code.
  • DAO (Data Access Objects): DAO was a technology that was used to extract data from Jet Databases.
  • RDO (Remote Data Objects): RDO was a thin layer of API over ODBC. It was somewhat like an add-on for ODBC.
  • OLEDB: OLEDB is a system level API created by Microsoft, which uses its Universal Data Access strategy. It can extract data from relational and non-relational data sources.
  • ADO (ActiveX Data Objects): ADO is an enhanced version of DAO and RDO. ADO uses the OLEDB technology to gain access to any kind of data. You can interact with OLEDB directly but that would be difficult in any language that doesnít support pointers, such as Visual Basic. As OLEDB is at the system level, you would have to take care of many things like memory management, object creation and destruction and other system level purposes. ADO is entirely based on COM. Itís a high level interface for using OLEDB. ADO provides us with an object oriented API to interact with a data source.
ADO consists mainly of three objects. The Connection, Command and RecordSet Objects:

Connection: This object is responsible for the connection to the data source. It encapsulates the details of a connection to the data source. You would have to supply the necessary details to this object in order to connect to the data source. All this information is bundled into one line called the ConnectionString. The open method of the Connection object accepts the ConnectionString as a parameter.

Command: This object is responsible for executing SQL statements and stored procedures.

Recordset: This object is responsible for storing the results returned by the data source. The recordset object also maintains all locking issues at the program level, NOT at the database level. Again, the data in the record set can be manipulated which in turn will be manipulated in the database.

Smart Pointers
I would also like to explain another concept before we proceed. It's about something called smart pointers. Smart pointers were made primarily to make programming a lot simpler. A smart pointer is a class that contains a pointer to another object. When you make an object of the smart pointer and call its methods, you are actually calling the methods of the interface, which is encapsulated in the smart pointer.

The smart pointer overrides the -> operator, which we use to call its methods. The smart pointer would ask you for the CLSID of the class which we want to use. Calling the CoCreateInstance method to create the object and other information related to creating the object is all encapsulated.

If smart pointers sound confusing then hopefully the code in the next couple of pages in this article will help to explain how they work.

Before you proceed, make sure you have worked with Visual C++ before to understand the following steps.
blog comments powered by Disqus
C++ ARTICLES

- Intel Threading Building Blocks
- Threading Building Blocks with C++
- Video Memory Programming in Text Mode
- More Tricks to Gain Speed in Programming Con...
- Easy and Efficient Programming for Contests
- Preparing For Programming Contests
- Programming Contests: Why Bother?
- Polymorphism in C++
- Overview of Virtual Functions
- Inheritance in C++
- Extending the Basic Streams in C++
- Using Stringstreams in C++
- Custom Stream Manipulation in C++
- General Stream Manipulation in C++
- Serialize Your Class into Streams in C++

Watch our Tech Videos 
Dev Articles Forums 
 RSS  Articles
 RSS  Forums
 RSS  All Feeds
Write For Us 
Weekly Newsletter
 
Developer Updates  
Free Website Content 
Contact Us 
Site Map 
Privacy Policy 
Support 

Developer Shed Affiliates

 




© 2003-2017 by Developer Shed. All rights reserved. DS Cluster - Follow our Sitemap
Popular Web Development Topics
All Web Development Tutorials