beginners tutorial - Learn VB6
VB6 tutorial - Learn Advanced VB6
VB .NET - Learn Visual Basic .NET
Analysis - System analysis and Design tutorial for Software Engineering
You are here: Visual
Basic > Advanced VB6 tutorial
> Chapter 8
Initializing the Connection Object in Code (VB6)
A Connection object provides you with a connection to the data that the Command
object will operate on and the Recordset will retrieve. If you plan to connect your Recordset
to data outside of your application, you must have at least one Connection object in the application.
The minimum steps you need to take to have a functional Connection object
are as follows:
STEP BY STEP
8.7 Establishing a Connection Object
Make sure that you have set a reference to the ADO Library, as discussed in
Chapter 8 - Database Access Management with ADO, under
the section "Programming with ADO."
Declare an object variable whose type is ADODB.Connection. If you want to program
the event procedure of the object, use the WithEvents keyword.
Set the Connection object's ConnectString property to reflect a valid OLE DB
provider, or specify the provider string in the next step, as follows:
cnNWind.ConnectString = "Provider=Microsoft.Jet.OLEDB.3.51;"
Call the Connection object's Open method. If you didn't specify the ConnectString
property in the preceding step, you need to pass the connection string as the
first argument to the Open method, as in the following example :
"Data Source= C:\DataSamples\Nwind.mdb"
<< Previous | Contents
| Next >>