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.

This is sample code. Add error handling and adjust to your requirements as necessary.

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
Your rating: None Average: 4.7 (3 votes)