add a new DataColumn and set its Expression to "AVG(YourColumn)" or "StDev(YourColumn)"DataTable.Columns.Add("NewColumn",typeof(Decimal),"AVG(YourColumn)");then
Decimal d = (Decimal)DataTable.Rows[0]["NewColumn"];
other aggregates:
Sum (Sum)
Avg (Average)
Min (Minimum)
Max (Maximum)
Count (Count)
StDev (Statistical standard deviation)
Var (Statistical variance)

解决方案 »

  1.   

    思归,我这样写:
    DS.Tables["ClassScore"].Columns.Add("NewColumn",typeof(Decimal),"AVG(DS.Tables['ClassScore'].Columns['Score'])" );//错误
            
    Decimal d=(Decimal)DS.Tables["ClassScore"].Rows[0]["NewColumn"];
            
    Response.Write(d);报错:System.Data.SyntaxErrorException: 聚合参数中的语法错误:需要具有可能的“Child”限定符的单个列参数。
    能再帮我看看吗?谢谢!
      

  2.   

    DS.Tables["ClassScore"].Columns.Add("NewColumn",typeof(Decimal),"AVG(DS.Tables['ClassScore'].Columns['Score'])" );/应该是DS.Tables["ClassScore"].Columns.Add("NewColumn",typeof(Decimal),"AVG(Score)" )