更改数据字段值
首先,我有最后一次从数据库更新文件
DataTable excelData = ReadSCOOmega(lastUploadFile);
,之后迭代这个数据
foreach (DataRow currentRow in rows) { currentRow. }
是否有可能在foreach循环中更改da数据。我只能访问这些数据的值
currentRow.Field<object>("Some column name")
但不改变它。我的想法被选中。我在Excel文件中有多个交易,何时上传到数据库,我需要在这个文件进行更改。这是可能的,或者我需要将数据存储在其他集合?
您可以使用索引器来设置存储在字段中的数据: currentRow["columnName"] = value
。
请参阅MSDN DataRow.Item属性
你可以这样做:
foreach (DataRow currentRow in excelData.Rows) { currentRow.BeginEdit(); currentRow["ColumnName"] = value; //..... currentRow.EndEdit(); }