In Dynamics AX, you can use ADO.NET to retrieve data from external data sources. This is quite easy to do for text and numeric data types, but not for Date or DateTime data types.
If you try a simple assign, you’ll end up throwing an exception:
blocks.Field1 = reader.get_Item( "REGISTRATIONDATE" );
Error executing code: Wrong argument types in variable assignment.
Using SqlDataReader.GetDataTypeName() to check the data type, it shows DateTime2. The destination field is a datetime field, but this problem as well as the solution happens even for plain date fields.
So, we might try to use SqlDataReader.GetDateTime() instead, but that results in exactly the same error.
Continue reading “Retrieving date/datetime from ADO.NET into a record field”