How to get the data for last row in datatable

I need to get the entire data of last row in datatable

For ex:

A. B

  1. Type
    
  2.    Type
    

So i need to get the last row

Output should be
A. B

  1. Type
    
1 Like

@sruthesanju

Dt.Rows(dt.Rowcount-1) will give you the last row of a datatable

You can add column names to access each column data of last row as Dt.Rows(dt.Rowcount-1)("Columnname").ToString

Cheers

Hi,

If you need the last row of datatable as DataRow type, the following will work.

dt.AsEnumerable.Last

If you need the last row of datatable as DataTable type, can you try the following?

{dt.AsEnumerable.Last}.CopyToDataTable

Regards,

How to remove the last row

Hi,

Can you try the following?

dt.AsEnumerable.Take(dt.Rows.Count-1).CopyToDataTable

Regards,

1 Like

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