Converting ADO Recordset to Cursor with CursorAdapter

CursorAdapter can easily convert ADO recordset into a VFP cursor. It does not support conversion in opposite direction.

$SAMPLECODE$

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34

CLOSE DATABASES ALL

*----- Part 1 -----*
* Create a recordset 
* Sql Server name/address
lcSqlServer = "SQLTEST1"
* SQL 2000 sample DB
lcDb  = "Pubs"
lcSql = "SELECT * FROM Sales"

* Open ADO connection 
oCon = CREATEOBJECT("ADODB.Connection")
oCon.Open("Provider=SQLOLEDB.1;Integrated Security=SSPI;Persist Security Info=False;" + ;
			"Initial Catalog=" + lcDb + ";Data Source=" + lcSqlServer)
* Create recordset
oRS = oCon.Execute(lcSql)

*----- Part 2 -----*
* Convert the ADO recordset to VFP cusor using CursorAdapter
oCA = CREATEOBJECT("CursorAdapter")
* Assign a cursor name
oCA.Alias = "crsRS"
oCA.DataSourceType = "ADO"
* Fill the cursor from the recordset
oCA.CursorFill(,,,oRS)
* Detach cursor so it still be open after CursorAdapter is destroyed
oCA.CursorDetach()
* Destroy CursorAdapter 
oCA = NULL

BROWSE LAST NOWAIT

Comments

Thank you very much!!!
I have searched the similar solution for a long time...
Thank you again!

Thank you very much for this issue.
I would like to ask you whether is possible to set column types in cursor created by CursorAdapter.
As I use a column containing some rows with numbers and other rows with words together, so this column is set as numeric via CursorAdapter. In this case the character information is lost.
I need a way to set the column type to be character, so the character information will be filled in as well.
If you have time to answer me, please send your answer to my email address: meryh@abv.bg.

Thank you in advance.
Best regards,
Maria