forum

Home / DeveloperSection / Forums / How to find max value of a column in a datatable?

How to find max value of a column in a datatable?

Mark Devid 2462 27-Jan-2014

I am trying to find the max value of a column in a datatable.

 Below is my code:-

var maxVal = dsloadReferralCodes.Tables["dtReferralCodesTable"].AsEnumerable().Max(r =>  Convert.ToBoolean(int.TryParse(r.Field<string>("ROWNUM"), out intROWNUM)) ? (int?)intROWNUM : null);

and below id the error i am getting while trying to get the max value and assigning it to intROWNUM

Unable to cast object of type 'System.Decimal' to type 'System.String'

Can someone help me in resolving the issue. This has been troubling me since long.

Thanks in advance...


c# c# 
Updated on 27-Jan-2014

Can you answer this question?


Answer

1 Answers

Liked By