Ways to add data column with dynamic type according to the input's data type

What I want is when the program iterates through a json object, if it sees the current field’s value is integer/string/double/etc, it dynamically adds a new column with that type to the dt.

Right now I’m using value.GetType.ToString and switch to manually define each cases. Just wondering if there’s a way to add data column with dynamic type.

Trying to get this code working but typeof keeps throwing error in uipath.

dt.Columns.Add(key, typeof(System.String))

As long there is no data within the col then you can set it also afterward after adding by

Got it working by getting the input’s type with GetType then pass it to the invoke code activity.

dt.Columns.Add(key, columnType)

Thank for your help nevertheless!

Note for myself:

dt.Columns.Add(“name”, GetType(System.String)) works but
dt.Columns.Add(“name”, typeof(System.String)) doesn’t for some reason

This topic was automatically closed 3 days after the last reply. New replies are no longer allowed.