While clearing a copy of a datatable, the original and the copy gets cleared.
Steps to reproduce:
- Initialize a datatable (say
DT1) with some content (I used a Read Range activity to read from excel and store in datatable)
DT2 = DT1
Clear Data Table
DT2 become null
DT2 should become null
Last stable behavior: NA
Last stable version: NA
OS Version: Windows 7
Others if Relevant: (workflow, logs, .net version, service pack, etc):
I believe this is an issue of the assignment being by reference instead of by value. When you’re doing your assignment
DT2 = DT1, you’re not doing an actual copy of the data. Both variables at that point, DT2 and DT1 are pointing to the same DataTable. So any changes done with one will be reflected in calls to the other.
Please see this documentation for how to do a copy: DataTable.Copy Method (System.Data) | Microsoft Docs
Yeah, he is correct. When you do DT2 = DT1, they are both the same data table.
Here’s a solution, which I use whenever I need a new table with the same data:
DT2 = DT1.AsEnumerable.CopyToDatatable
Thanks @dmccammond and @ClaytonM. Problem solved now
Both the ideas work!
This topic was automatically closed 3 days after the last reply. New replies are no longer allowed.