0

So here is the problem statement. I have a datatable with two columns BUDGET and ACTUAL. I have a button click event where I want to copy all the budget values to actual values in the same table. I don't want looping and I also tried merge and it did not work. Is there any other approach ? Any help would be appreciated.

Thanks

Vasanth
  • 31
  • 3

2 Answers2

1

I know this question is very old but I found it looking for something similar, so maybe it still can help someone else. I think the following line would solve it - I'm not sure if Array.ForEach should be considered as a loop in the asker circumstances, what I tried to avoid was writing a For Each loop explicitly.

Array.ForEach(dt.AsEnumerable().ToArray(), Sub(row) row("ACTUAL") = row("BUDGET"))

Based on @Kusal's answer here.

mbd
  • 346
  • 1
  • 9
-1

There is a built in function in DataTable (Copy)

DataTable.Copy();

http://msdn.microsoft.com/en-us/library/system.data.datatable.copy(v=vs.110).aspx

Atir Naveed
  • 629
  • 5
  • 3
  • 2
    DataTable.Copy() does not copy one column value to another column in same table. Does it ? – Vasanth Dec 22 '14 at 17:34
  • 1
    Please check the link you mentioned. It copies the structure and data from one `DataTable` to another. Not from one `DataColumn` to another in the same `DataTable`. – Ravindra Gullapalli Jul 30 '17 at 11:20