1

这是 C# Winforms。

我在这段代码中有一个字符串列表:

List<string> WaveAndPickFields = new List<string>(new string[] { "ID", "TransactionID", "OrderNumber", "WarehouseID", "StoreOrderNumber", "OrderType", "CustomerID", "CustomerPONumber", "DepartmentCode", "LoadNumber", "ReverseLoadSequence", "BOLNumber", "MasterBOLNumber", "ProNumber", "Carrier", "CarrierSCAC", "FreightTerms", "RushOrderFlag", "OrderEntryDate", "ExpectedCarrierArrivalDate", "DatePromised", "OrderWeight", "OrderCubicVolume", "OrderCartonCounts", "ShippingShort", "PrepaidFreight", "CODAmount", "InsuranceAmount", "PIPAmount", "TotalFreightCost", "ShipToCustomerCode", "ShipToName", "ShipToAddress1", "ShipToAddress2", "ShipToAddress3", "ShipToCity", "ShipToState", "ShipToZipCode", "ShipToCountryCode", "ShipToCountryName", "BillToCustomerCode", "BillToName", "BillToAddress1", "BillToAddress2", "BillToAddress3", "BillToCity", "BillToState", "BillToZipCode", "BillToCountryCode", "BillToCountryName", "DeliveryAddressName", "DeliveryAddress1", "DeliveryAddress2", "DeliveryAddress3", "DeliveryCity", "DeliveryState", "DeliveryZipCode", "DeliveryCountryCode", "DeliveryCountryName", "DeliveryPhone", "BillFreightCustomerCode", "BillFreightAddressName", "BillFreightAddress1", "BillFreightAddress2", "BillFreightAddress3", "BillFreightCity", "BillFreightState", "BillFreightZipCode", "BillFreightCountryCode", "BillFreightCountryName", "CartonLabel", "ShipVerificationFlag", "PartialOrderFlag", "EarliestShipDate", "LatestShipDate", "EarliestDeliveryDate", "LatestDeliveryDate", "PromoCode", "Route", "Stop", "ToteFlag", "Status" });

我要做的就是遍历这段代码并将一堆字段添加到数据表中。我在这段代码中这样做:

foreach (string field in WaveAndPickFields)
{
    dtWaveAndPicks.Columns.Add(field);
}

我也试过:

for (int i = 0; i < WaveAndPickFields.Count; i++)
{
    DataColumn column = new DataColumn(WaveAndPickFields[i]);
    dtWaveAndPicks.Columns.Add(column);
}

无论出于何种原因,这些行似乎都在执行,但整个函数都停止了,并且在没有异常错误的情况下没有其他任何执行。

dtWaveAndPicks.Columns.Add(field);

和:

dtWaveAndPicks.Columns.Add(column);

有谁知道为什么会这样?对我有用的替代方法是有一条将添加一列的行。问题是,当我可以有这样的循环时,我不想有 80 多行来添加字段。

4

1 回答 1

1

我强烈建议使用 windbg 来确定这里发生了什么 - 如果你之前没有使用过它可能会有点令人生畏,但有相当不错的教程(特别是来自 Tess,请参见此处

安装 windbg 后,在挂起时通过任务管理器获取进程转储 打开 windbg 中的转储文件

然后运行.symfix c:\sos修复符号路径

下一次加载 sos.loadby sos mscorwks

最后检查任何线程运行的异常.foreach (ex {!dumpheap -type Exception -short}){.echo "********************************";!pe –nested ${ex} }

试一试,看看你的进展如何

于 2013-06-13T14:59:41.567 回答