I have the below code which is attempting to modify each row in a DataTable but after the loop over the rows where modification takes place, when I look at the rows collection the column LOCATION is empty even though the loop just populated it. Can anyone help?
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();
}
}
I don’t know much about
DataViewsbut I would guess that theToTable()is creating new instances of the rows.Try modifying the loop to