Project Test.exe raised exception class EVariantTypeCastError with message 'Could not convert v
环境:ABFramework3.9.5
错误描述:循环插入报如题所示错误
代码如下:
rstUpSalesDetail.FieldByName('CustGoodsCode').AsString:=rstSourceData.FieldByName('CustGoodsCode').AsString;
rstUpSalesDetail.FieldByName('BrandID').AsString:=rstSourceData.FieldByName('BrandID').AsString;
rstUpSalesDetail.FieldByName('DistrictID').AsString:=rstSourceData.FieldByName('DistrictID').AsString;
rstUpSalesDetail.FieldByName('Field1').AsString:=rstSourceData.FieldByName('Field1').AsString;
rstUpSalesDetail.FieldByName('Field2').AsString:=rstSourceData.FieldByName('Field2').AsString;
rstUpSalesDetail.FieldByName('Field3').AsString:=rstSourceData.FieldByName('Field3').AsString;
rstUpSalesDetail.FieldByName('Field4').AsString:=rstSourceData.FieldByName('Field4').AsString;
rstUpSalesDetail.FieldByName('Field5').AsString:=rstSourceData.FieldByName('Field5').AsString;
vFieldTypeNames:=FieldTypeNames[rstSourceData.FieldByName('BoxQty').DataType];
vFieldTypeNames:=FieldTypeNames[rstUpSalesDetail.FieldByName('BoxQty').DataType];
rstUpSalesDetail.FieldByName('BoxQty').AsInteger:=rstSourceData.FieldByName('BoxQty').AsInteger;
rstUpSalesDetail.FieldByName('UnitPrice').AsCurrency:=rstSourceData.FieldByName('UnitPrice').AsCurrency;
rstUpSalesDetail.FieldByName('DiscountRate').AsCurrency:=rstSourceData.FieldByName('DiscountRate').AsCurrency;
rstUpSalesDetail.FieldByName('PurchaseOrderID').AsString:=OrderABQuery.FieldByName('PurchaseOrderID').AsString;
rstUpSalesDetail.FieldByName('SalesOrderDetailID').AsString:=rstSourceData.FieldByName('OrderDetailID').AsString;
rstUpSalesDetail.FieldByName('SalesOrderID').AsString:=OrderDetailABQuery.FieldByName('SalesOrderID').AsString;
for i:=1 to MaxSizeCol do
rstUpSalesDetail.FieldByName('x_'+IntToStr(i)).AsInteger:=rstSourceData.FieldByName('x_'+IntToStr(i)).AsInteger;
rstUpSalesDetail.FieldByName('SizeIndex').AsInteger:= MaxSizeCol;
执行到BoxQty赋值时报错
经过排查是因为设置了字段CustGoodsCode的取值SQL是:箱*数量和,所以执行到箱时就会报 type (String) into type (Double)的错误