Sunday, November 16, 2014

Method to get the Sum of specified column in the datatable

  /// <summary>
        /// Returns the Sum of specified column in the datatable
        /// </summary>
        /// <param name="columnName"></param>
        /// <param name="dtSource"></param>
        /// <returns>Decimal. The source column should be in decimal format</returns>
        public static decimal GetColumnTotal(string columnName, DataTable dtSource)
        {
            decimal total = 0;
            try
            { total = dtSource.AsEnumerable().Sum(o => Convert.ToDecimal(o.Field<object>(columnName))); }
            catch
            { }
            return total;
        }

No comments:

Using Authorization with Swagger in ASP.NET Core

 Create Solution like below LoginModel.cs using System.ComponentModel.DataAnnotations; namespace UsingAuthorizationWithSwagger.Models {     ...