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!
3 Likes
Yoichi
(Yoichi)
May 25, 2022, 11:07pm
2
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,
3 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).
4 Likes
Thank you both for replying so quickly. Both ideas work!
postwick
(Paul Ostwick)
May 26, 2022, 8:56pm
5
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.
system
(system)
Closed
May 29, 2022, 8:57pm
6
This topic was automatically closed 3 days after the last reply. New replies are no longer allowed.