2014年7月13日 星期日

[RESOLVED] how to use SUM with datatable


Hi,



my code:


var result = from posts in Slip_DataTable.AsEnumerable()
where posts.Field("BettingSlipNr") == optionalSlipMenu.SelectedValue
select new
{
DateOfEvent = posts.Field("DateOfEvent"),
NameOfEvent = posts.Field("NameOfEvent"),
TypeOfBets = posts.Field("TypeOfBets"),
Pick = posts.Field("Pick"),
Odds = posts.Field("Odds"),
Stake = posts.Field("Stake"),
StakeSum = posts.Field("StakeSum"),
//Id = posts.Field("Id"),
BettingSlipNr = posts.Field("BettingSlipNr"),
};

        lblNumberOfRows.Text = Convert.ToString(result.Count());
lblTotalOdds.Text = Convert.ToString(result.

How to use SUM Odds in lblTotalOdds?



Thanks.







does this work?


lblNumberOfRows.Text = Convert.ToString(result.Count());
lblTotalOdds.Text = Convert.ToString(result.Compute("Sum(Odds)", "");

hope this helps...



Compilation Error


Description:
An error occurred during the compilation of a resource required to service this request. Please review the following specific error details and modify your source code appropriately.




Compiler Error Message: CS1061: 'System.Data.EnumerableRowCollection' does not contain a definition for 'Compute' and no extension method 'Compute' accepting a first argument of type 'System.Data.EnumerableRowCollection'
could be found (are you missing a using directive or an assembly reference?)



oh! instead of filtering datatable records using linq expression, simply try this


lblTotalOdds.Text = Convert.ToString(Slip_DataTable.Compute("Sum(Odds)", "BettingSlipNr=" + optionalSlipMenu.SelectedValue);

hope this helps...


沒有留言:

張貼留言