LINQ | Filter DataTable | Get Matched Row Index

Lets say a datatable with 4 columns col1, col2, col3, col4.

Need to filter this datatable (on col2 and col3) with 2 string values. If matched found, need to get the matched row index number.

I want to use Linq Query.

1 Like

Hey @Arup,

Here is the solution

DT_Test.Rows.IndexOf((DT_Test.AsEnumerable.Where(function(row) (row(“col2”).ToString.Equals(“String1”) or row(“col2”).ToString.Equals(“String2”)) and (row(“col3”).ToString.Equals(“String1”) or row(“col3”).ToString.Equals(“String2”))).First))

This will find the index of only the first match, if you want for every match then you can workaround by a loop or another nested LINQ.

Meanwhile, you can also even try Select statement to achieve the same.

Let me know for any queries.



can do it via index list
it returns -1 in case of it is not found

(From i In Enumerable.Range(0,dtData.Rows.Count)
Let r = dtData.Rows(i)
Where r(1).toString.Equals(“M#A”) And r(2).toString.Equals(“M#B”)
Select i).DefaultIfEmpty(-1).First

find starter help here:
FindRowIndex_FirstMatch_2Cols.xaml (6.9 KB)


Hi @ppr can u please help me to with linq query to delete first 10 rows in datatable or to select datatable from row 11. Quick help will be great!
Thanks in advance!!

Kiruthika R

Hello @Kiruthika_Ravichandran - Use below one to skip first 10 rows in a data table or to select from 11th row. Take assign activity

variable of type data table output = DT.AsEnumerable.Skip(10).CopyToDataTable

It will copy the data starting from 11th row to output variable

1 Like

@ushu Thank you very much

@ushu is there a way to unmerge the columns in the datatable?