LINQ - Search data table and return row index

Using LINQ, I’m look for a way to search a data table (dt_Table) and return the row index of a row that matches three column values:

  • Column “Line No” = in_LineNumber
  • Column “Release No” = in_ReleaseNumber
  • Column “Quantity” = in_Quantity

Any suggestions?

Thanks in advance!

1 Like

Hi,

Can you try the following expression?

dt.AsEnumerable.Where(Function(r) r("Line No").ToString=in_LineNumber AndAlso r("Release No").ToString=in_ReleaseNumber AndAlso r("Quantity").ToString=in_Quantity).Select(Function(r) dt.Rows.IndexOf(r)).ToArray()

This returns array of Int32 type as result.

Regards,

2 Likes

DT.Asenumerable.Tolist.Findindex(Function(r) r(“Column1”).Tostring.Equals(Val1) And r(“Column2”).Tostring.Equals(Val2) And r(“Column3”).Tostring.Equals(Val3))

Output Datatype(int32).

1 Like

Thank you both for replying so quickly. Both ideas work!

Just so you know, LINQ isn’t faster than just doing it with activities (For Each etc).

LINQ is still looping through the data. It’s just hidden behind an abstraction layer.

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