Set Column Datatype dynamically while adding a new Column to the Datatable

Hi All,
I want to create a datatable and during the runtime only i will be getting the table and column properties. so here I am trying to set the column datatype based on the input in 2 different ways but neither of them are working.

1st way :
ColumnName- System.Data.Datacolumn datatype
Dt1- Datatable
InputDatatype - String with value (“int32”)
In Assign activity,
ColumnVariable=dt1.Columns.Add(“NewColumn”)
dt1.Columns(“NewColumn”).DataType=typeof(NewColumn)
dt1.Columns(“NewColumn”).MaxLength=10

i am getting the below error.

2nd way:
Using Invoke Code

ColumnVariable=dt1.Columns.Add(“NewColumn”);
dt1.Columns(“NewColumn”).DataType=typeof(NewColumn);
dt1.Columns(“NewColumn”).DataType=Length;

I am getting the below errror.

Can anyone please help on this.
@loginerror @Anthony_Humphries @Palaniyappan

Hi @Raju23c,

Please try these.

2 Likes

This worked perfectly…Thanks a lot @GreenTea .

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