Add data column to datatable and set same value to every row

Hi, I would like to add data column to a datatable and the value for every row in that data column should equal to the same value.

Is there a way to quickly achieve it than to use for each & assign?

Hi @inyourgravity

See these

These might be helpful, give it a try

Thanks,
Prankur

1 Like

Hi, so I’ve tried this

DataColumn = Dt.Columns.Add(“Col Name”, GetType(String), DateTime.toString)

and got this
Invoke workflow file: Assign : Syntax error: Missing operand after ‘18’ operator.

Have no idea what “18” is

Try Invoke Code instead of Assign activity.

Not sure how do I use it?
I’m not very familiar with codes

In Invoke Code activity,

Place this - Dt.Columns.Add(“Col Name”, GetType(String), DateTime.toString)

That’s it.

Regards,
Karthik Byggari

For adding a column you can use Add Data Column activity, it is the simplest

image

image

Thanks,
Prankur

1 Like


Still getting the same error

But After i’ve added the data column, is there a way to assign value of each row in that datacolumn to a specific value without using for each row + assign?

See this sample

Main.xaml (10.0 KB)

This will show you how to add column then insert value with and without foreach

Thanks,
Prankur

Hi @inyourgravity
as mentionned in one of the answers tagged by @PrankurJoshi the syntax to add val to a specific row for a specific column is

dt1.Rows(numrow).Item(“Column”) = "Value"

Here is a xaml file to illustrate this enjoy :wink:

Main.xaml (7.6 KB)

@inyourgravity

Try to assign default value in the Add Data Column Activity.

Other Wise
Let us take the Datatable as dta
dtb= dta
Add Data Column to dta.

dta= (From p in dta.Select
        Select ( dta.Rows.Add(p.ItemArray,strValue))).ToArray.CopyToDataTbale

strValue is the value you want to assign to that column.

Regards
Mahesh

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