在 AX 2012 中使用数组导入多个邮政地址

发布于 2024-12-29 08:34:09 字数 1282 浏览 1 评论 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++;
}

I am using the following code to import multiple postal addresses for a customer record in AX 2012 =(Microsoft Dynamics AX) using AIF=(Application Integration Framework). I am testing this code with a customer record with two postal addresses. The very first time the code runs (1 st loop), it goes through just fine, but on the second round it fails, giving me array out of bound error. Any suggestions on what might be causing this error looking at the below code?

   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++;
}

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

甜中书 2025-01-05 08:34:09

我猜测,但看起来您正在将 tmp 记录添加到另一个数组中,而该数组的大小尚未增加。

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

List<AxdEntity_DirPartyPostalAddressView> tmplist = new List<AxdEntity_DirPartyPostalAddressView>();

I am guessing, but it appears like you are adding you tmp record into another array, which you haven't increased in size.

Why don't you use lists instead?

List<AxdEntity_DirPartyPostalAddressView> tmplist = new List<AxdEntity_DirPartyPostalAddressView>();
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文