Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- DataTable dt = WhateverCreatesDataTable();
- DataRow dr = dt.Rows[0];
- int sum = dt.Columns.Cast<DataColumn>().Sum(dc=>(int)dr[dc]);
- DataTable dt = WhateverCreatesDataTable();
- DataRow dr = dt.Rows[0];
- int sum = 0;
- foreach(DataColumn dc in dt.Columns)
- sum += (int)dr[dc];
- DataColumn totalColumn = new DataColumn();
- totalColumn.DataType = System.Type.GetType("System.Int32");
- totalColumn.ColumnName = "Total";
- totalColumn.Expression = "Product1 + Product2 + Product3 + Product4 + Product5";
- // Populate and get the DataTable dt then add this computed column to this table
- dt.Columns.Add(totalColumn);
- //Now if you access the column "Total" of the table you will get the desired result.
Add Comment
Please, Sign In to add comment