Obter a última linha de um data table

Olá pessoal, qual expressão ou qual passo a passo preciso fazer para obter a última linha de uma tabela?

myLastRow | DataRow = YourDataTableVar.AsEnumerable().Last()

Hi @amanda.gondim

Just another approach to keep dt type

dtResult.AsEnumerable().Skip(dtResult.RowCount - 1).CopyToDataTable()


Variations for keeping the dt type (when not Legecy)
dtLastOnly = YourDataTableVar.AsEnumerable().TakeLast(1).CopyToDataTable

1 Like

Hi @amanda.gondim

Read the excel data and store it in a datatable variable here dtx is a datatable variable.
Lastrow is of system.data.datarow datatype.
the lastRow variable will contain the last row of the table as a DataRow object. You can then access specific values in that row using column names or indices.


Hope it helps!!