Microsoft Knowledge Base Article
This article contents is Microsoft Copyrighted material.
©2005-©2007 Microsoft Corporation. All rights reserved.
Terms
of Use |
Trademarks
Article ID: 194517 - Last Review: July 13, 2004 - Revision: 3.2
How To Use Creatable ADO Recordsets in Visual FoxPro
This article was previously published under Q194517
Often, you find a need for temporary storage for data. ADO 2.x enables you
to create recordsets on the fly for this purpose.
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
APPLIES TO
- Microsoft Visual FoxPro 6.0 Professional Edition
- Microsoft Data Access Components 2.1 Service Pack 2
- Microsoft Data Access Components 2.6
| kbdatabase kbhowto KB194517 |
Community Feedback System
Very often, it takes hours to solve a problem. Very often, you've looked high
and low, and have tried a lot of solutions. When you finally found it, chances
are, it was because someone else helped you. Here's your chance to give back.
Use our community feedback tool to let others know what worked for you and what
didn't.
Please also understand that the community feedback system is not warranted to be
correct, it's simply a system that we've built to let people try and help each
other. If something in a feedback response doesn't make sense to you, or you're
not comfortable making changes that the feedback talks about (like registry
edits), please consult a professional.
Thank you for using kbAlertz.com Feedback System.
-- Scott Cate