BUG: RStoCursor in Vfpcom.dll File Does Not Work with Certain Data Types (262067)



The information in this article applies to:

  • Microsoft Visual FoxPro for Windows 3.0
  • Microsoft Visual FoxPro for Windows 3.0b
  • Microsoft Visual FoxPro for Windows 5.0
  • Microsoft Visual FoxPro for Windows 5.0a
  • Microsoft Visual FoxPro for Windows 6.0

This article was previously published under Q262067

SYMPTOMS

Microsoft Visual FoxPro developers often make use of the VFPCOM Utility, which is available for download from the Microsoft Visual FoxPro Web site. Among other things, this sample allows users to convert an ADO recordset into a FoxPro cursor through its RSToCursor() method.

When you attempt to create a cursor from an ADO recordset by using the RSToCursor() method, the numeric, float, and Double data types are not converted properly. This behavior results in a -10 return code from the object, and the FoxPro cursor is not created.

Additional information on the Vfpcom sample and its error codes may be found in the "References" section later in this article.

RESOLUTION

There is a Microsoft Visual FoxPro RS2DBF function inside of the program named RS2DBF.PRG that converts an ADO recordset to a Visual FoxPro cursor and retains numeric, float, and Double data types.

More information and a download point can be found at this Microsoft Web site:

STATUS

Microsoft has confirmed that this is a bug in the Microsoft products that are listed at the beginning of this article.

MORE INFORMATION

Steps to Reproduce Behavior

  1. If you have not done so already, download and unzip the VFPCOM Utility from the Microsoft Visual FoxPro samples Web site.
  2. Follow the instructions in the "Installation and Setup" section of the Vfpcom.htm file that accompanies the sample.
  3. Copy the following code to a new program, and then run it to demonstrate the problem. Note that there is a return value from the Vfpcom.dll of -10 ("Failed to create Fox cursor"). This occurs when the utility tries to convert an ADO Recordset with one float, numeric or double field, into a Fox cursor.
    ******************************* START CODE *******************************
    CLEA
    LOCAL loVFPCOM, loRS, lnError
    
    loVFPCOM = CREATEOBJECT("vfpcom.comutil")
    IF VARTYPE(loVFPCOM) # 'O' OR ISNULL(loVFPCOM)
    	MESSAGEBOX("Problem creating VFPCOM Object. Exiting")
    	RETURN .F.
    ENDIF
    
    
    *~ Let's try with a cursor with one, NUMERIC field
    MAKE_CURSOR('NUMERIC')
    ? "*** NUMERIC FIELD TEST ***"
    loRS = CREATEOBJECT("adodb.recordset")
    lnError = loVFPCOM.CURSORTORS(loRS)
    ? "CursorToRs Err Code for table with 1 NUMERIC field... ", TRANSFORM(lnError)
    lnError = loVFPCOM.RSTOCURSOR(loRS, "test")
    ? "RStoCURSOR Err Code for table with 1 NUMERIC field... ",  TRANSFORM(lnError)
    ?
    loRS = NULL
    RELEASE loRS
    *~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    
    
    *~ Let's try with a cursor with one, FLOAT field
    MAKE_CURSOR('FLOAT')
    ? "*** FLOAT FIELD TEST ***"
    loRS = CREATEOBJECT("adodb.recordset")
    lnError = loVFPCOM.CURSORTORS(loRS)
    ? "CursorToRs Err Code for table with 1 FLOAT field... ", TRANSFORM(lnError)
    lnError = loVFPCOM.RSTOCURSOR(loRS, "test")
    ? "RStoCURSOR Err Code for table with 1 FLOAT field... ",  TRANSFORM(lnError)
    ?
    loRS = NULL
    RELEASE loRS
    *~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    
    
    *~ Let's try with a cursor with one, DOUBLE field
    MAKE_CURSOR('DOUBLE')
    ? "*** DOUBLE FIELD TEST ***"
    loRS = CREATEOBJECT("adodb.recordset")
    lnError = loVFPCOM.CURSORTORS(loRS)
    ? "CursorToRs Err Code for table with 1 DOUBLE field... ", TRANSFORM(lnError)
    lnError = loVFPCOM.RSTOCURSOR(loRS, "test")
    ? "RStoCURSOR Err Code for table with 1 DOUBLE field... ", TRANSFORM(lnError)
    ?
    loRS = NULL
    RELEASE loRS
    *~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    
    *~ Clean-up
    loRS = NULL
    loVFPCOM = NULL
    RELEASE loRS, loVFPCOM
    
    *~~~~~~~ PROCEDURES ~~~~~~~~~~~~~
    
    PROCEDURE MAKE_CURSOR(lcFldType)
    	DO CASE
    		CASE lcFldType = 'NUMERIC'
    			CREATE CURSOR test(n_num N(5))
    
    		CASE lcFldType = 'FLOAT'
    			CREATE CURSOR test(floatfld F(10))
    
    		CASE lcFldType = 'DOUBLE'
    			CREATE CURSOR test(dobfld B(2))
    	ENDCASE
    
    	LOCAL i
    	FOR i = 1 TO 10
    		INSERT INTO test VALUES(i)
    	NEXT i
    ******************************* END CODE *******************************
    					

REFERENCES

For additional information, click the article numbers below to view the articles in the Microsoft Knowledge Base:

235985 INFO: Error Codes for VFPCOM Utility

192692 Rs2dbf.exe Converting ADO 2.x Recordset to VFP Cursor

(c) Microsoft Corporation 2000, All Rights Reserved. Contributions by Trevor Hancock, Microsoft Corporation.


Modification Type:MajorLast Reviewed:5/12/2003
Keywords:kbbug kbCodeSnippet kbDatabase kbOOP kbpending KB262067