Data table column to list with no duplication

Hello all

agian i found solution in VB

> Blockquote

but not c#
i have data table want to create list of customer name without duplication ,
Then i need to query the data table against the customer name so i have small datatable with only one customer rows,

Any tips !

Hi @Hazem_Saleh ,

I believe the c# Representation would be as below :

DT.AsEnumerable().Select(r=>r("Customer Name Column").ToString()).Distinct().ToList()

Let us know if this doesn’t work

1 Like
  • As mentioned by @supermanPunch
  • Also as an option using YourDataTableVar.DefaultView Approach
  • in newer LINQ (depending on selected TargetFramework) DistinctBy Operator
1 Like

Thanks,
i have this issue "Method name expected "
image

DT.AsEnumerable().Select(r=>r["Customer Name Column"].ToString()).Distinct().ToList()

try [ ]

1 Like

Thanks
but cant covert list to a string!

im trying fetchDataDT_IN.AsEnumerable().Select(r=>r [“COMPANYNAME”]).select (r=>r.tostring())Distinct().ToList(); but still no luck

@Hazem_Saleh ,

We see a Difference in the expression in the Screenshot and the one you have provided in the form of text below it.

Could you double check on the expression used ?

Good morning,

Blockquote fetchDataDT_IN.AsEnumerable().Select(r=>r [“COMPANYNAME”]).ToString().Distinct().ToList().ToString();
if i dont use the last .tostring i get this error

@Hazem_Saleh ,

There is a misplace of brackets in your Expression.

Have you Checked with the Suggestion already provided above :

We don’t see this exact expression used in your workflow.

DataTable.AsEnumerable().Select(Function(x) x(“Column1”).ToString()).Distinct().ToList()

Pls try this this will work

@Hazem_Saleh if that will work then pls mark it as solution for my hard work

we just summarize the given inputs:

And counterchecked:

Kindly note: the needed statement ending ;

And Also:
grafik

So with the help from @supermanPunch you should finalize it and get it working, when:

  • statements are carefully ported to your code
  • any specifics (e.g. variablename, columnnames…) are edited as needed

Hi @Hazem_Saleh ,

We can have C# linq’s in the Invoke Code activity as shown below,

companyNames(List of String) = dt1.AsEnumerable().Select(ra => ra.Field<String>("COMPANYNAME")).Distinct<String>().ToList<String>();

We have to set the language to CSharp in Invoke Code activity property section as per below screenshot,

Arguments:-

Hope this may help you :slight_smile:

4 Likes

Thanks icant find list as a type
do i need to defined it first ?

Thanks its working now :slight_smile:

Hello again,
Is it possible to do the same but we get the datatable with the row Values!

Maybe you are looking for the following:

grafik

Thanks, but i still want to have the raw values under this unique column names,

ABC,1
CDE,2

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