VB6 beginners tutorial - Learn VB6

Advanced VB6 tutorial - Learn Advanced VB6

Systems 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:

8.7 Establishing a Connection Object

  1. 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."

  2. Declare an object variable whose type is ADODB.Connection. If you want to program the event procedure of the object, use the WithEvents keyword.

  3. 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;"

  4. 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 :

    cnNWind.Open "Provider=Microsoft.Jet.OLEDB.3.51;" & _
    "Data Source= C:\DataSamples\Nwind.mdb"

See Also


<< Previous | Contents | Next >>

Home | About Us | Privacy Policy | Contact Us

Copyright © | All Rights Reserved