Hi,
im using ax2012. Anyone know how to view code CLRObject class? i want to capture null value from staging, how to do that…because currently i got error when i trigger null value from staging(sql server r2 2008) to ax.
my code is like this :
System.Data.SqlClient.SqlDataReader _sqldatareader;
_tblVend.Currency = _sqldatareader.get_Item(“Currency”);
let say the field from staging is null, ax will get the error .
the error is :
Clr Interop Marshal: Unsupported type.
CLR object cannot be marshaled to Microsoft Dynamics anytype.
thanks in advance…
Your code tries to assign an instance of System.DBNull class to a string field, which is obviously not supported. Actually, there is no conversion from DBNull to any X++ type.
Use IsDBNull() method to identify null values - then you can assign the default value for the given X++ type, throw an exception or do whatever else is appropriate in your case.
And to answer your question about CLRObject class - you can view its code, it’s provided in a compiled form only.
By the way, I would recommend another approach - it’s much less work to use LINQ to SQL, encapsulate that in a .NET library and use it in X++ via .NET Interop. I have much more positive experience with that than with using SqlDataReader directly.
Thanks for reply,
"Use IsDBNull() method to identify null values - then you can assign the default value for the given X++ type, throw an exception or do whatever else is appropriate in your case. "
i don’t understand above idea… what do u mean by assign the default value?
Something like this:
int columnNum = _sqldatareader.GetOrdinal("Currency");
if (_sqldatareader.IsDBNull(columnNum))
{
tblVend.Currency = "";
}
else
{
tblVend.Currency = sqldatareader.GetString(columnNum);
}
Thank you so much…
my solution is solved…thanks again