Microsoft KB Archive/198379

= BUG: Decimal Points Truncated Using RDO Client Batch Cursors =

Article ID: 198379

Article Last Modified on 3/14/2005

-

APPLIES TO


 * Microsoft Visual Basic 5.0 Enterprise Edition
 * Microsoft Visual Basic 6.0 Enterprise Edition

-



This article was previously published under Q198379



SYMPTOMS
When you try to retrieve or update a Remote Data Object (RDO) Column of type DECIMAL, the value truncates to only four digits to the right of the decimal point. This happens only when using the RDO client batch cursors.



CAUSE
When using an RDO client batch cursor, the DECIMAL value of the RDO Column is mapped as a CURRENCY data type instead of a DECIMAL data type. This causes all decimal values with a scale of four or more to truncate.

NOTE: The CURRENCY data type gives decimal values accurate up to 19 digits, with only four digits to the right of the decimal point.



RESOLUTION
Here are four possible ways to work around this decimal truncation problem:
 * Define the data types of the columns on your backend table to be of type FLOAT instead of type DECIMAL. -or-


 * Use the ODBC cursor library or server-side cursors instead of the client batch cursor library. -or-


 * Use an rdoQuery object to explicitly map the values correctly. For more information, please see the Sample Workaround code that follows. -or-


 * Use ActiveX Data Objects (ADO) instead of RDO. For more information, please see the Sample Workaround code that follows.

Sample Workaround Code
To test the code samples, first use ISQL/W to create the test table.  In ISQL/w, select the Pubs database.  Copy the following code into ISQL/w's Query window, then click the Execute button: CREATE TABLE dbo.Table1 (        ID int Primary Key,         DecValue decimal(20, 8) NULL  )

  Add a record to the new table, by executing the following code in ISQL/W: INSERT dbo.Table1 VALUES (1, 11.12345678)

 If you do not already have a system data source name (DSN) named Pubs, use the ODBC Administrator in Windows Control Panel to create a system DSN named Pubs that points to the Pubs database.

Workaround Using the rdoQuery Object
 Create the test table, Table1, and the Pubs DSN as described in steps 2-4 of the Sample Workaround Code section.</li> In Visual Basic, create a new Standard EXE project.</li> Add a Command button to Form1.</li> From the Project menu, choose References and then add a reference to "Microsoft Remote Data Object 2.0".</li>  Paste the following code into the Click event of the Command button: Dim cn As New rdoConnection Dim qry As rdoQuery

cn.CursorDriver = rdUseClientBatch cn.Connect = "DSN=Pubs;UID=;PWD=;Database=Pubs" cn.EstablishConnection rdDriverNoPrompt, False

Set qry = cn.CreateQuery("", "Update Table1 Set DecValue = ? " & _                              "Where ID = 1")

qry.rdoParameters(0).Direction = rdParamInput qry.rdoParameters(0).Value = 22.12345678 qry.Execute

qry.Close cn.Close

</li> Run the sample application.</li>  In ISQL/W, confirm that the Update was successful by running the following: SELECT * FROM dbo.Table1

</li></ol>

Workaround using ADO
 Create the test table, Table1, and the Pubs DSN as described in steps 2-4 of the Sample Workaround Code section.</li> In Visual Basic, create a new Standard EXE project.</li> Add a Command button to Form1.</li> From the Project menu, choose References then add a reference to "Microsoft ActiveX Data Objects Library 2.x."</li>  Paste the following code into the Click event of the Command button: Dim cn As New ADODB.Connection Dim rsADO As New ADODB.Recordset

cn.CursorLocation = adUseClient cn.Open "DSN=pubs;UID=;PWD=;Database=Pubs"

rsADO.Open "SELECT * FROM Table1", cn, adOpenStatic, _ adLockBatchOptimistic

rsADO!DecValue = 33.12345678 rsADO.UpdateBatch

rsADO.Close cn.Close

</li> Run the sample application.</li>  In ISQL/W, confirm that the Update was successful by running the following: SELECT * FROM dbo.Table1

</li></ol>

<div class="status_section">

STATUS
Microsoft has confirmed this to be a bug in the Microsoft products listed at the beginning of this article.

<div class="moreinformation_section">

Steps to Reproduce Behavior
 Create the sample table in the Pubs database as described in steps 1-4 of the Sample Workaround Code section.</li> <li>In Visual Basic, create a new Standard EXE project.</li> <li>Add a Command button to Form1.</li> <li>From the Project menu, choose References then add a reference to "Microsoft Remote Data Object 2.0".</li> <li> Paste the following code into the Click event of the Command button: Dim cn As New rdoConnection Dim rsRDO As rdoResultset

cn.CursorDriver = rdUseClientBatch cn.Connect = "DSN=Pubs;UID=;PWD=;Database=Pubs" cn.EstablishConnection rdDriverNoPrompt, False

Set rsRDO = cn.OpenResultset("SELECT * FROM Table1", rdOpenKeyset, _                 rdConcurBatch)

rsRDO("ID").KeyColumn = True

rsRDO.Edit rsRDO!DecValue = 44.12345678 MsgBox rsRDO!DecValue '<--- Value is always chopped here.

rsRDO.Update rsRDO.BatchUpdate

rsRDO.Close cn.Close

</li> <li>Run the sample project. Notice that the DECIMAL value truncates to only four digits to the right of the decimal point. That is, the message box displays 44.1235.</li> <li> In ISQL/W, confirm that the Update was unsuccessful by running the following code: SELECT * FROM dbo.Table1

Note that Value is reported to be 44.12350000. </li></ol>

<div class="references_section">