First I have last update file from DB
DataTable excelData = ReadSCOOmega(lastUploadFile);
, after this iterate over this data
foreach (DataRow currentRow in rows)
{
currentRow.
}
Is that possible to change da data in the foreach loop.I can access only the value of this data
currentRow.Field<object>("Some column name")
but not to change it.My idea is selected.I have a multiple deals in excel file and when is upload to DB, I need to make changes in this file.Is that possible or I need to store the data in other collection?
To create a new DataRow, use the NewRow method of the DataTable object. After creating a new DataRow, use the Add method to add the new DataRow to the DataRowCollection. Finally, call the AcceptChanges method of the DataTable object to confirm the addition.
To add a new row, declare a new variable as type DataRow. A new DataRow object is returned when you call the NewRow method. The DataTable then creates the DataRow object based on the structure of the table, as defined by the DataColumnCollection.
A DataRow is created by calling the NewRow( ) method of a DataTable , a method that takes no arguments. The DataTable supplies the schema, and the new DataRow is created with default or empty values for the fields: // create a table with one column DataTable dt = new DataTable(); dt. Columns.
You can do that like :
foreach (DataRow currentRow in excelData.Rows)
{
currentRow.BeginEdit();
currentRow["ColumnName"] = value;
//.....
currentRow.EndEdit();
}
You can use indexer to set the data stored to the field: currentRow["columnName"] = value
.
See MSDN DataRow.Item Property
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With