Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations dencom on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

create cursor from ado recordset

Status
Not open for further replies.

vfpgolfer

Programmer
Oct 16, 2004
76
US
I can create the cursor in a class but can't see it on my form. I am trying to simulate extracting data from an MSSQL data container into an adorecordset then into a cursor that I can read. If i put code in prg without the define clas then works ok - but i need in a class (COM) as other programmers using diff language will use this. How can I see the cursor created in vfp. Here is code that creates class and gets cursor:

DEFINE CLASS disbdescrfile as Custom olepublic

PROCEDURE getcode
* this procedure verifies existance of a code and returns .T. if exists, .F. if doesn' exist.
LPARAMETERS lccode

SELECT id FROM descr WHERE ALLTRIM(id)=ALLTRIM(lccode) INTO CURSOR tempdescr
IF _tally=0
RETURN .F.
ELSE
RETURN .T.
endif

PROCEDURE getdisbdescrfile
LOCAL loConn AS ADODB.CONNECTION, ;
loCommand AS ADODB.COMMAND, ;
loException AS EXCEPTION, ;
loCursor AS CURSORADAPTER

** ADO
loConn = CREATEOBJECT('ADODB.Connection')
WITH loConn
.ConnectionString = 'Provider = VFPOLEDB; Data Source = ESILaw.DBC'
.OPEN()
ENDWITH

loCommand = CREATEOBJECT('ADODB.Command')
loCommand.ActiveConnection = loConn

** Put the result (RecordSet) into a VFP cursor
loCursor = CREATEOBJECT('CursorAdapter')
WITH loCursor
.ALIAS = 'Descr'
.DATASOURCETYPE = 'ADO'
.SELECTCMD = ;
'SELECT * FROM Descr WHERE type="D"'
.DATASOURCE = CREATEOBJECT('ADODB.Recordset')
.DATASOURCE.ActiveConnection = loConn
llReturn = .CURSORFILL(.F., .F., 0, loCommand)

ENDWITH
RETURN
enddefine

here is small prg I am using to test getting the cursor back to vfp:
myvar1=CREATEOBJECT("disbdescrfile.disbdescrfile")
myvar1.getdisbdescrfile()

SELECT descr && I have tried (myvar1.locursor) (myvar1)
BROWSE normal

What do I need on the select - or is it even possible or do we have to return the adorecordset to vfp then create cursor?

 
Hi vfpgolfer,

Well, it's a good idea have only one data access class for both vfp and external languages. But why don't you turn it around: for foxpro applications, just use the normal way to instanciate the class and first create a foxpro cursor with SQL-Passthrough.

Then secondly convert the vfp cursor to an ado recordset.
There is the vfpcom.dll or the dbf2rs.prg from ken levy to do this, although they both have their limits and maybe the cursoradapter will do this slower for vfp use but faster for external apps.

I have very little experience with Cursoradaptor, as I still do VFP7 mostly. Have you read about Cursoradapter in the Fox Wiki? and perhaps take a look at Mark McCasland's examples:

I think it should be .CURSORFILL(.F., .F., -1, loCommand),
-1 is the default for nOptions, especially with "ADO".

If that still rises errors, you should call AERROR and get further information about the error.

Bye, Olaf.
 
Thanks for the tips Olaf, I download the zip with samples and will look at tomorrow. The reason I am doing this is because we want to store the data in mssql server and allow third party to access using language other than vfp. I will let you know when (if!!) we get it working
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top