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

Dynamic Recordsets - Visual Basic 6 (VB6)

A dynamic Recordset object never uses a connection object and has nothing to do with any sort of external data storage.

To implement a dynamic Recordset, you never associate it with a Connection object. Instead, you dynamically define its structure by adding Field objects to its Fields collection. It is then up to the application (perhaps with the user's help) to populate the Recordset with rows and manipulate its data.

Your code should take the following steps to implement a dynamic Recordset:

  1. Determine ahead of time the field structure that you want for each row of the dynamic Recordset.

  2. Declare a Recordset object variable, but don't associate it with a Connection.

  3. Repeat the following steps for each field that you want in the Recordset's structure:

    • Call the Append method of the Recordset object's Fields collection to add the Field to the Recordset's Fields.

    • In the first and second arguments of the Append method, set the Field object's Name and Type properties, respectively. If the Field has a type that can vary in size (such as BSTR, a Basic String type), also set its AssignedSize property in the third argument.

    • Repeat these steps for each Field that you want to have in the Recordset.

  4. Call the Recordset object's Open method.

  5. Load the Recordset with initial data through user edits and/or your own processing logic. Use the Recordset techniques discussed in this chapter.

  6. Manipulate the data in the Recordset through user edits and/or your own processing logic. Again, use the Recordset techniques discussed in this chapter.

Listing 8.14 gives an example of code that implements a dynamic Recordset with offline processing.


Set rs = New ADODB.Recordset
rs.CursorLocation = adUseClient
rs.Fields.Append "FirstName", adBSTR, 25
rs.Fields.Append "LastName", adBSTR, 25
'After this point, programming is identical
'to manipulating any other type of
'ADO Recordset object

See Also


<< Previous | Contents | Next >>

Home | About Us | Privacy Policy | Contact Us

Copyright © | All Rights Reserved