I want to copy itemarray[4] of datatable to itemarray[6] of that datatable. I used this code and I didn’t see any changes:
foreach (DataRow dr_row in dt_table.Rows)
{
foreach (var field_value in dr_row.ItemArray)
{
object cell_data = field_value;
if (dr_row.ItemArray[6].ToString() == "")
{
dr_row.ItemArray[6] = dr_row.ItemArray[4];
}
original_data += cell_data.ToString();
}
original_data += Environment.NewLine;
}
First of all never do this:
Change it to this:
or:
However, that is just good practice. Now, to the problem that you are facing.
What the
Itemarraydoes is, it creates a new array from the row, so that if you change the array, you do not change the row.Do this:
Should work.