How to convert data table row values into array?

I had datatable with one column name “ID” , it has 100 rows. i need to store these 100 values in one array! is that possible?

1 Like

Hi @MitheshBolla

Checkout this expression

If you dont want duplicatie

dt.DefaultView.ToTable(true, "ID").AsEnumerable().Select(Function (a) a(0).ToString).ToArray()

If You want duplicate

dt.DefaultView.ToTable(False, "ID").AsEnumerable().Select(Function (a) a(0).ToString).ToArray()

Regards
Sudharsan

1 Like

Hi @MitheshBolla

How about this expression?

stringArr = dataTable.Rows(0).ItemArray.Select(Function (x) x.ToString().Trim).ToArray()

Regards
Gokul

@MitheshBolla
Please use an assign activity, create an array variable then

dt.AsEnumerable.Select(function(x) x(“Column1”).Tostring).ToArray

can i have this in C#?

@muhamed_fasil

Checkout this expresion use in invoke code

here are parameters

Without Duplicate

Str1 =Dt.AsEnumerable().Select(r => r.Field<string>("ID")).ToArray();
Str1= Str1.Distinct().ToArray();

With Duplicate

Str1 =Dt.AsEnumerable().Select(r => r.Field<string>("ID")).ToArray();

To print the array in message box use this expression

String.join(",",ArrCol)

Hope this Helps!

Regards
Sudharsan

1 Like

hi @MitheshBolla

If your query got resolved can you mark the appropriate post as solution so that it will be helpful to others with the same query

Happy Autoamation!!

Regards
Sudharsan

1 Like

Hi , thanks it worked, i tested now

1 Like


getting error! while invoking

Can you share the screenshot of arguments?

1 Like

Hi @MitheshBolla ,

I believe your project is already in c#, So you could use the code directly in an Assign Activity instead of using Invoke Code Activity.

Try using the code suggested by @Sudharsan_Ka directly in Assign Activity and let us know what error messages occur.

1 Like

Invoke code: Exception has been thrown by the target of an invocation.

1 Like

Invoke code: Exception has been thrown by the target of an invocation.

1 Like

i kept in and out for DT

@MitheshBolla ,

What is the data type of AllLegalMatterIds variable ? It should be a Datatable.

1 Like

yes , it is datatable

As you provided modified code , i directly placed in Assign activity! There is no validation error!

But when i run code , i am getting error as

can you please help me at this point bro!

Still getting same error, all arguments are also correct!