GET NUMBER OF ROW

Hi everyone,

I made a consult from excel to obtain the cell value of certain row with linq,
I built this expression “(From row In dtVariable.AsEnumerable()
Where row (“Column4”).ToString.Contains(“TOTAL”)
Select row (“Column10”))(0).ToString” and it works, this gives me the value of the total in a string variable, but I need the row number too. Any idea to how to get the row number of this row?

Hi,

You can try with these expression datable.Asenumerable.Tolist.Findindex(Function(x) x(“Column1”).Tostring.Equals(Val1) And x(“Column2”).Tostring.Equals(Val2) And x(“Column3”).Tostring.Equals(Val3))

Output type should be Int32.

Regards
Naman

Hi @marquezd

Can you try below

totalRow = (From row In dtVariable.AsEnumerable()
            Where row("Column4").ToString.Contains("TOTAL")
            Select row).FirstOrDefault()

totalRowDataType: System.Data.DataRow

rowIndex = dtVariable.Rows.IndexOf(totalRow)
cellValue = totalRow("Column10").ToString()

Regards,

1 Like

@marquezd

Try this

Rowindex = dt.Rows.IndexOf(dt.AsEnumerable Where(function(row) row ("Column4").ToString.Contains("TOTAL"))

Cheers

1 Like

Tnks both of you, it works with the solutions

2 Likes

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