0

我正在使用以下代码使用 AIF=(应用程序集成框架)在 AX 2012 =(Microsoft Dynamics AX)中导入客户记录的多个邮政地址。我正在使用具有两个邮政地址的客户记录测试此代码。代码第一次运行(第一次循环)时,它运行得很好,但在第二轮它失败了,给了我数组超出范围的错误。查看以下代码,对可能导致此错误的原因有何建议?

   index = 0;

    AxdEntity_DirPartyPostalAddressView[] array = new  AxdEntity_DirPartyPostalAddressView[index];

foreach (DataRow row2 in row.GetChildRows("HdrLine"))
{

    AxdEntity_DirPartyPostalAddressView address = 
                                   new AxdEntity_DirPartyPostalAddressView

     {
         LocationName = row2["AXDirPartyPostalAddress_LocationName"].ToString(),
         Street = row2["AXDirPartyPostalAddress_Street"].ToString(),
         City = row2["AXDirPartyPostalAddress_City"].ToString(),
         State = row2["AXDirPartyPostalAddress_State"].ToString(),
         CountryRegionId = row2["AXDirPartyPostalAddress_Country"].ToString(),
         ZipCode = row2["AXDirPartyPostalAddress_zipcode"].ToString(),
         Roles = row2["AXDirPartyPostalAddress_AddRoles"].ToString()
     };

    Array.Resize<AxdEntity_DirPartyPostalAddressView>(ref array, index + 1);
    array[index] = address;

    custTable.DirParty[index].DirPartyPostalAddressView = 
                    new AxdEntity_DirPartyPostalAddressView [] { array[index] };
    index++;
}
4

1 回答 1

1

我在猜,但看起来你正在将 tmp 记录添加到另一个数组中,而你没有增加它的大小。

为什么不使用列表来代替?

List<AxdEntity_DirPartyPostalAddressView> tmplist = new List<AxdEntity_DirPartyPostalAddressView>();
于 2012-01-27T07:54:03.143 回答