How To Use Creatable ADO Recordsets in Visual FoxPro (194517)



The information in this article applies to:

  • Microsoft Visual FoxPro for Windows 6.0
  • Microsoft Data Access Components 2.1 SP2
  • Microsoft Data Access Components 2.6

This article was previously published under Q194517

SUMMARY

Often, you find a need for temporary storage for data. ADO 2.x enables you to create recordsets on the fly for this purpose.

MORE INFORMATION

The following example creates an ADO recordset with an integer, varchar and date field, adds two records to it, and displays the contents of all fields in the recordset on the desktop:
   * Demonstrates creating a temporary recordset in ADO
   * Program creates a recordset, adds an integer, varchar
   * and date field, adds two records, and displays the
   * contents of all fields on the desktop

   #DEFINE ADUSECLIENT 3
   #DEFINE ADLOCKBATCHOPTIMISTIC 4
   #DEFINE ADINTEGER 3
   #DEFINE ADVARCHAR 200
   #DEFINE ADDATE 7
   #DEFINE ADFLDISNULLABLE 0x00000020
   #DEFINE ADOPENSTATIC   3

   oRecordSet = CREATEOBJECT("ADODB.Recordset")

   WITH oRecordSet
      * specify client-side cursors
      .CURSORLOCATION = ADUSECLIENT

      * add 3 fields
      .FIELDS.APPEND ("Key", ADINTEGER)
      .FIELDS.APPEND ("Data1", ADVARCHAR, 40, ADFLDISNULLABLE)
      .FIELDS.APPEND ("Data2", ADDATE)

      * open the recordset
      .OPEN(,,ADOPENSTATIC, ADLOCKBATCHOPTIMISTIC)

      * add a couple of records
      .ADDNEW
      .FIELDS("Key").VALUE = 1
      .FIELDS("Data1").VALUE = "String1"
      .FIELDS("Data2").VALUE = DATE()

      .ADDNEW
      .FIELDS("Key").VALUE = 2
      .FIELDS("Data1").VALUE = "Another string"
      .FIELDS("Data2").VALUE = {^1992/01/06}
   ENDWITH

   * read the records back
   oRecordSet.Movefirst
   DO WHILE ! oRecordSet.EOF
      ? oRecordSet.FIELDS("Key").VALUE, ;
         oRecordSet.FIELDS("Data1").VALUE, ;
         oRecordSet.FIELDS("Data2").VALUE
      oRecordSet.MoveNext
   ENDDO
				

Modification Type:MinorLast Reviewed:7/13/2004
Keywords:kbDatabase kbhowto KB194517