更改Datarow字段值

时间:2016-05-10 17:09:37

标签: c# excel datarow

首先我有DB的最后更新文件

DataTable excelData = ReadSCOOmega(lastUploadFile);

,在此迭代此数据之后

foreach (DataRow currentRow in rows)
{
     currentRow.
}

是否可以在foreach循环中更改da数据。我可以仅访问此数据的值

currentRow.Field<object>("Some column name")

但不要改变它。我的想法被选中。我在excel文件中有多个交易,当上传到DB时,我需要在这个文件中进行更改。这是可能的还是我需要将数据存储在其他文件中集合?

2 个答案:

答案 0 :(得分:9)

你可以这样做:

foreach (DataRow currentRow in excelData.Rows)
{
    currentRow.BeginEdit();
    currentRow["ColumnName"] = value;
    //.....
    currentRow.EndEdit();
}

答案 1 :(得分:6)

您可以使用索引器设置存储在字段中的数据:currentRow["columnName"] = value

请参阅MSDN DataRow.Item Property