Freetutes.com

VB6 beginners tutorial - Learn VB6

Advanced VB6 tutorial - Learn Advanced VB6

VB .NET - Learn Visual Basic .NET

Systems Analysis - System analysis and Design tutorial for Software Engineering


You are here: Visual Basic > Advanced VB6 tutorial > Chapter 8

Recordsets - Command Object Events in VB6

The general steps you need to take to initialize a data-connected Recordset in your code are as follows:
  1. Make sure you have a valid Connection or Command object.

  2. Declare an object variable of the type ADODB.Recordset.

  3. Set the Source property (typically, a SQL statement or the name of a stored procedure or table) and the ActiveConnection property (use the Set = syntax to cause this property to point to a valid ADO Connection object). You can also omit this step and pass information about the Source and ActiveConnection as arguments in the next step.

  4. Call the Recordset's Open method. If you omitted step 3, indicate the Recordset's Source and ActiveConnection as the Open method's first and second arguments, respectively.

Listing 8.2 illustrates the property-driven technique described in step 3 for opening a Recordset.

LISTING 8.2
OPENING AN ADO RECORDSET BY SETTING THE ACTIVECONNECTION AND SOURCE PROPERTIES

Set cnNWind = New ADODB.Connection
Set rsEmployees = New ADODB.Recordset
Dim sConnect As String
sConnect = "Provider=Microsoft.Jet.OLEDB.3.51;" & _
"Data Source= NWind.mdb"
cnNWind.Open sConnect
rsEmployees.Source = "Select * From Employees Order By
LastName,FirstName"
Set rsEmployees.ActiveConnection = cnNWind
rsEmployees.Open

Listing 8.3 illustrates the use of command-line arguments to accomplish the same result, as discussed in step 4.

LISTING 8.3
OPENING AN ADO RECORDSET WITH ARGUMENTS TO THE OPEN METHOD

Set cnNWind = New ADODB.Connection
Set rsEmployees = New ADODB.Recordset
Dim sConnect As String
sConnect = "Provider=Microsoft.Jet.OLEDB.3.51;" & _
"Data Source= NWind.mdb"
cnNWind.Open sConnect
rsEmployees.Open _
"Select * From Employees Order By LastName,FirstName", _
cnNWind

NOTE - Other Methods for Opening a Recordset: The section titled "Accessing Data with the Execute Direct Model" in the following chapter discusses how to use the Execute method of ADO Connection and Command objects to open a Recordset.

See Also


  

<< Previous | Contents | Next >>

Home | About Us | Privacy Policy | Contact Us

Copyright © Freetutes.com | All Rights Reserved