I have datatable and a list of string (having years) need a select query to fetch those records from datatble that is containing the items from list

I have datatable and a list of string (having years) need a select query to fetch those records from datatble that is containing items from the list

Hi @sheetal_Bora
please follow these steps.
1-Read range and store data in DT
2-use For each loop over string array.
3- inside loop use filter data and give string value “item” inside filter data.
4-use merge activity inside loop.

Thanks

It’s a list of string

@sheetal_Bora That’s why I am using loop. can u share list here

image

It will have these years comma seperated and say there is a datatble having a column event date like 01/01/2922 so only those records need to fetch which have years given in the list

yes you can filter datatable in loop of list but you will need to merge data against each item.

Hi @sheetal_Bora ,

Could you give an initial try with the below Linq :

FilterDT = DT.AsEnumerable.Where(Function(x)yourYearList.Any(Function(y)CDate(x("Event Date").ToString).Year.ToString.Equals(y))).CopyToDatatable

Here, FilterDT is a new Datatable, DT is your input Datatable, yourYearList is the list of years in String type. You could change the column name accordingly, assumed it is Event Date.

We also take note that a Direct CopyToDatatable gives an error if there are no filtered rows, hence we follow the post below :

Let us know if there are exceptions found and provide a Screenshot/Exception Message encountered.

How can hardcode a list of years and pass it in for each loop to test it

@sheetal_Bora
Thanks and Happy Learning

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