Now I whith my colleagues work on integration Axapta with the other business application named M&F (Management and Finance). Our company uses M&F for more than eight years and now it is time for new ERP system. This application has 2-tier architecture, and its business logic is on the server side. We use stored procedure API for document exchange from Axapta to M&F. Some days ago I tried to call stored procedure on MS SQL Server from X++. For several parameters it was necessary to set null value. At first I instantiated COMVariant like this:
COM parameter = new COM("ADODB.Parameter");
COMVariant nullParam = new COMVarian(ComVariantInOut::In, ComVariantType::VT_NULL);
;
parameter.name("@paramName");
parameter.type(#adInteger);
parameter.value(nullParam); // This method throw exception!
After several hours research I found decision of this problem:
COM parameter = new COM("ADODB.Parameter");
nullParam = new COMVariant();
;
parameter.name("@paramName");
parameter.type(#adInteger);
nullParam.variantType(ComVariantType::VT_NULL);
parameter.value(nullParam); // This method doesn`t throw exception now!
I think problem is in constructor of the COMVariant class. What is your opinion?
I think it would be reasonable to create specific method, which takes "_value" (anytype) and "_type" (AX type: Types enumeration) as the parameters and return COMVariant instance.
ОтветитьУдалитьThen you can implement parser inside (something like CCADOField.value()), which will take type and value into account:
if (value == 'NULL')
{
cOMVariant = new COMVariant(VT_NULL);
}
else
{
cOMVariant = new COMVariant();
switch (_type)
{
case Types::Integer:
comVariant = new ComVariant(VT_I32);
break;
case Types::Date:
...
}
}
return cOMVariant;
Then you'll have unified method for parameter value creation.