Find Last value of specific columns When Value in Rows is more than Column

Hi All,
I am working in a datatable having 3 different scenarios,

  1. I need to find Id Value = 2
  2. I need to find Id Value = 1
  3. I need to find Id Value = Null
    image .

I tired using the code : dt.Rows(dt.Rows.Count-1)(0).ToString but it’s reading the entire datatable and each time my output is coming as Null, the value from 3rd row.

Any help or Xaml will be appreciated.

In General you are interested on the Last col1 value that is Not empty or null If there IS No value
Then Null should be returned

With fetching the Last row the Last Not empty value was ignored and Not fetched.

To do this you can start with Filter Datatable and Filter to all is Not empty col1 rows. Depending on the row Count of Filter result the Last value or null can be fetched

Another approach Could be to do this all with LINQ, Bit First start with the Essential activities an do some plays

1 Like