Retrieving Double fields from ADO.NET in CIL code

I recently wrote about how to retrieve DateTime fields from ADO.NET.

If your code is running in CIL, there are some more gotchas, as some conversions that work just fine in X++ will fail when running in CIL.

If you try to retrieve a Double value from ADO.NET and assign it to a record buffer field, the code may run just fine in X++ but when running in CIL you may get this error message:

Error executing code: Wrong argument types in variable assignment.

To work around this, use a local bounce variable of type System.Double, then assign that to the record field like this:

System.Double clrDouble;

...

clrDouble = reader.get_Item( "UNITPRICE" );
item.Price = clrDouble;

There are likely to be other data types causing problems in CIL mode, so I’ll keep posting as I come across them.

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.