首页 > 代码库 > DataTable中某数字列数据相加

DataTable中某数字列数据相加

代码如下:

 //double num=dt.AsEnumerable().Select(row => Convert.ToDouble(row.Field<string>("Id"))).Sum();
 //double num2 = dt.AsEnumerable().Sum(row => Convert.ToDouble(row.Field<string>("Id")));
 double num = dt.AsEnumerable().Select(row => Convert.ToDouble(row["Id"])).Sum();
 double num2 = dt.AsEnumerable().Sum(row => Convert.ToDouble(row["Id"]));

 

DataTable中某数字列数据相加