Friday, 20 April 2012

Find Min/Max Value FROM datatable


private void populateMaxOrMinValue(DataTable dtRef)
{
 if (dtRef.Rows.Count > 0)
        {
        //////////PICK THE MAX VALUE FROM DATATABLE USING ENUMERABLE
         maxValue = dtRef.AsEnumerable()
               .Where(ss => double.TryParse(ss["value"].ToString(), out val))
               .Select(ss => Convert.ToDouble(ss["value"])).Max();
         //////////PICK THE MIN VALUE FROM DATATABLE USING ENUMERABLE
         minValue = dtRef.AsEnumerable()
                .Where(ss => double.TryParse(ss["value"].ToString(), out val))
                .Select(ss => Convert.ToDouble(ss["value"])).Min();
         //////////////////////////////////////////////
 }
}

No comments:

Post a Comment

Get all non-clustered indexes

DECLARE cIX CURSOR FOR     SELECT OBJECT_NAME(SI.Object_ID), SI.Object_ID, SI.Name, SI.Index_ID         FROM Sys.Indexes SI             ...