在 AX 2012 中使用数组导入多个邮政地址
我使用以下代码使用 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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我猜测,但看起来您正在将 tmp 记录添加到另一个数组中,而该数组的大小尚未增加。
为什么不使用列表来代替呢?
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?