Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
VFP cursor to ADODB.RecordSet
Message
 
 
To
All
General information
Forum:
Visual FoxPro
Category:
Databases,Tables, Views, Indexing and SQL syntax
Title:
VFP cursor to ADODB.RecordSet
Environment versions
Visual FoxPro:
VFP 9 SP1
Miscellaneous
Thread ID:
01135897
Message ID:
01135897
Views:
245
I'm not able to find this answer anywhere. I've done a lot of code that takes an ADO recordset and converts it to a VFP cursor, but now I've got to find an easy way to go the other direction. Given a VFP cursor convert it directly to a recordset.

This code goes from RS to Cursor:
public oRS as ADODB.RecordSet, oCommand as ADODB.command

#DEFINE ADINTEGER   3
#DEFINE ADCHAR    129

oRS = CreateObject( "ADODB.RecordSet" )
oRS.CursorLocation = 3
ors.LockType = 3
oRS.Fields.Append( "c1", ADCHAR, 100 )
oRS.Fields.Append( "i1", ADINTEGER, 4 )
oRS.Open()

oRS.AddNew()
oRS.Fields("c1").Value = "test1"
oRS.Fields("i1").Value = 1

oRS.AddNew()
oRS.Fields("c1").Value = "test2"
oRS.Fields("i1").Value = 2

oRS.MoveFirst()
do while ! oRS.EOF()
   ? alltrim( oRS.Fields("c1").Value ), oRS.Fields("i1").Value
   oRS.MoveNext()
enddo

public oCursorAdapter as CursorAdapter

if ( used( "testthis" ) )
   use in testthis
endif

oCursorAdapter = createobject( "cursoradapter" )
oCursorAdapter.DataSourceType ="ADO"
oCursorAdapter.Alias = "testthis"

oCursorAdapter.DataSource = oRS

? oCursorAdapter.CursorFill( .f., .f., 0, oRS )

select testthis
scan
   ? alltrim( c1 ), i1
endscan
this doesn't generate a RS:
create cursor testthis ( i1 i, c1 c(10), t1 t, m1 m )
insert into testthis values ( 1, "test 1", datetime(), "this is my pretty memo" )
insert into testthis values ( 2, "test 2", datetime(), "this is my prettier memo" )

oRS = CreateObject( "ADODB.RecordSet" )
oRS.CursorLocation = 3
oRS.LockType = 3

oCursorAdapter = createobject( "cursoradapter" )
oCursorAdapter.DataSourceType ="ADO"
oCursorAdapter.DataSource = oRS
? oCursorAdapter.CursorAttach( "testthis", .t. )

oRS.MoveFirst()
do while ! oRS.EOF()
   ? alltrim( oRS.Fields("c1").Value ), oRS.Fields("i1").Value
   oRS.MoveNext()
enddo
Ideally I need the RS to construct its field collection structure directly from the cursor structure and then push the data into the RS. The CursorAttach() method returns .t. but oRS is pretty much an empty shell. What am I doing wrong/missing? I don't really want the run a select, it doesn't have to be updateable, it's just a RS that we are passing from a VFP COM object over to an ASP page.
df (was a 10 time MVP)

df FoxPro website
FoxPro Wiki site online, editable knowledgebase
Next
Reply
Map
View

Click here to load this message in the networking platform