如何使用'SUM'计算amount1和amount2?

时间:2010-11-24 07:59:35

标签: linq

如何使用'SUM'计算我的结果中的amount1和amount2,sum2?

 var sum2 = (from p in db.tbl_relacijes  
           select p);  

 Button12.Text = (sum2.Sum());

3 个答案:

答案 0 :(得分:2)

我假设relacijes有两列amount1和amount2

Button12.Text=sum2.Sum(a=>a.amount1 + a.amount2).ToString();

答案 1 :(得分:2)

很难确定你在问什么,假设表中的amount1和amount2列?

Button12.Text = sum2.Sum(row => row.amount1 + row.amount2).ToString();

答案 2 :(得分:1)

我必须说我真的没有问题,但也许这就是你要找的东西?

var sum2 = (from p in db.tbl_relacijes  
           select p);  

 Button12.Text = (sum2.Sum(t => t.amount1 + t.amount2)).ToString();