我有下面的代碼,它試圖修改DataTable中的每一行,但在循環修改發生的行之後,當我查看行集合時,LOCATION列是即使循環剛剛填充它也是空的。誰能幫忙?在循環中修改DataTable行不會持續更改
dtBoxes.Columns.Add("LOCATION");
dtBoxes.DefaultView.Sort = "PALLETID";
foreach (DataRow row in dtBoxes.DefaultView.ToTable().Rows)
{
var locationRow = dtLocations.Select("ID = " + row["ID"].ToString());
if (locationRow != null)
{
row["LOCATION"] = locationRow.First()["LOCATION"].ToString();
}
}
謝謝你的工作,但它保持數據表的順序? – Jon 2012-01-05 12:29:00
@Jon我不明白它會如何改變,但測試它。 – Ray 2012-01-05 13:17:46