How to Add an Aggregate Column?

Answer

Expression columns typically compute a value based on other columns in the same row. You can also add an expression column to a table that generates an aggregate value. In the absence of a filtering expression, aggregates always compute their totals using all rows in a table. This is also true of aggregate expression columns. When you add such a column to a table, that column will contain the same value in every row, and that value will reflect the aggregation of all rows in the table.

 

C#

DataTable sports = new DataTable("Sports"); sports.Columns.Add("SportName", typeof(string)); sports.Columns.Add("TeamPlayers", typeof(decimal)); sports.Columns.Add("AveragePlayers", typeof(decimal),    "Avg(TeamPlayers)");  
sports.Rows.Add(new Object[] {"Baseball", 9}); sports.Rows.Add(new Object[] {"Basketball", 5}); sports.Rows.Add(new Object[] {"Cricket", 11});  
MessageBox.Show((string)sports.Rows[0]["AveragePlayers"]);  // Displays 8.3... MessageBox.Show((string)sports.Rows[1]["AveragePlayers"]);  // Also 8.3...

All ado.net Questions

Ask your interview questions on ado-net

Write Your comment or Questions if you want the answers on ado-net from ado-net Experts
Name* :
Email Id* :
Mob no* :
Question
Or
Comment* :
 





Disclimer: PCDS.CO.IN not responsible for any content, information, data or any feature of website. If you are using this website then its your own responsibility to understand the content of the website

--------- Tutorials ---