这是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多行来添加字段。
答案 0 :(得分:1)
我强烈建议使用windbg来确定这里发生了什么 - 如果你没有使用它之前它有点令人生畏但是有很好的教程(特别是来自Tess see here)
安装windbg后,在挂起时通过任务管理器获取进程转储 在windbg中打开转储文件
然后运行.symfix c:\sos
以修复符号路径
下一步加载sos .loadby sos mscorwks
最后检查任何线程运行.foreach (ex {!dumpheap -type Exception -short}){.echo "********************************";!pe –nested ${ex} }
试试这个&amp;看看你如何上场