12-10-2016, 04:21 PM
1458837267-Smiley004.pdf (Size: 48.14 KB / Downloads: 8)
Preface
This is Part 2 in a 2 part series on using Visual Basic 6 to connect to an Oracle
database. In Part 1, I showed you how to use an ADO Data Control to make the
connection. In this article, I show you how to use ADO Objects to make the
connection. Not only will the article be useful for the Oracle programmers in the
audience, it will also show you how to use ADO objects in your program.
ADO Objects
What's an Object? Hopefully you've read by well-received book, Learn to
Program with Visual Basic 6 Objects. As much as I would love to spend a lot of
time discussing object variables in detail, I'm going to presume that you know
what they are and how, in a nutshell, they refer to an object instantiated from a
class or template.
Having said that, I will tell you that the ADO Object model can be confusing,
particularly because there are frequently many ways to achieve the same
functionality.
In this article, we will create an ADO Connection Object, then use an ADO
Command Object to return the results of a query to an ADO Recordset object.
Finally, as an added bonus, I'll show you something that your average
programmer doesn't know can be done--we'll set the Recordsource of an ADO
DataGrid to the recordset we produce in code. In other words, without the ADO
Data Control, we'll populate a DataGrid.
Similar to what we did when we added the ADO Data Control to our Visual Basic
Toolbox, in order to use ADO Objects we must first set a reference to the ADO
Object Library. The version of the ADO Object Library installed on your PC will
vary depending upon a number of factors-the PC I'm using as I write this article
contains ADO Version 2.x.
To add a reference, select Project-References from the Visual Basic Menu Bar,
then select Microsoft ActiveX Data Objects 2.6 Library. If the version number
doesn't match yours exactly, that's fine---just be sure to select the ActiveX Data
Objects Library, not the ActiveX Data Objects Recordset Library that follows it in
the list. Be sure that you select Project-References, NOT Project-Components.