Adrian_Star
(Adrian Starukiewicz)
April 14, 2021, 7:22pm
1
Hi,
After calling the SQL query by Execute Query Activity
the result is stored in System.Data.DataTable
, which inherits the column schema from core SQL Data Base, eg. DateTime
, Double
.
I want to clone this table to a new one:
The new table is to contain the general layout of the old table, that is: all columns and their names .
The new table must not contain restrictions on the data type it stores and values.
Visualization:
From this:
To this:
How can this be achieved?
I need to make changes to the data in the table. For example, convert Double (0,155) to a value expressed in % (15,5%), change the date format, etc.
After changes: new table will looks like:
ppr
(Peter Preuss)
April 14, 2021, 7:29pm
2
@Adrian_Star
newDT = OldDT.Clone
afterwards you can finetune / adopt the cloned Datatable
as it looks that you are only interested on the columnnames as alternate do following:
For each activity - TypeArgument: String - Values: oldDT.Columns.Cast(of DataColumn).Select(Function (x) x.ColumnName).toArray
so you will iterate over the names and can used within an add DataColumn on a new DataTable
1 Like
Adrian_Star
(Adrian Starukiewicz)
April 14, 2021, 7:39pm
3
I’ve tried, but Clone clones the structure of the DataTable , including all DataTable schemas and constraints.
After Clone old data table to new one I have error:
RemoteException wrapping System.ArgumentException: Input string was not in a correct format.Couldn't store <15%> in Dbl Column. Expected type is Double. ---> RemoteException wrapping System.FormatException: Input string was not in a correct format.
I also tried:
.DefaultView().ToTable()
and it doesn’t work either.
ppr
(Peter Preuss)
April 14, 2021, 7:41pm
4
please read again the post and give a try on second option.
DataTableVar.Clone will keep the datatype
Adrian_Star
(Adrian Starukiewicz)
April 14, 2021, 7:49pm
5
Works!
Is there any function / method or LINQ available to not do it in a for each loop?
DT_Old.Columns.Cast(of DataColumn).Select(Function (x) x.ColumnName).toArray
ppr
(Peter Preuss)
April 14, 2021, 8:12pm
6
it could look like this:
Variables:
flow:
Result:
Kindly note: this approach risks to fall into a blackbox case and it is up to your code guideline / development rules to use it or not.
1 Like
system
(system)
Closed
April 17, 2021, 8:13pm
7
This topic was automatically closed 3 days after the last reply. New replies are no longer allowed.