Click here to Skip to main content
15,895,423 members
Please Sign up or sign in to vote.
1.00/5 (2 votes)
See more:
I have a data table. how to add sum function to this query?

C#
var qry = from rows in dtTempTbl.AsEnumerable()
                                 orderby rows["RowId"] ascending
                                 group rows by new { PositionID = rows["ItemSubGroupId"] } into grp
                                 select grp.First();
Posted
Comments
Tomas Takac 4-Dec-14 7:33am    
Sum of what? Could you be more specific?

Hi,

MSDN has a great site where you can find many useful LINQ examples.

https://code.msdn.microsoft.com/LINQ-Aggregate-Operators-c51b3869[^]

Cheers!
 
Share this answer
 
v2
Comments
BillWoodruff 4-Dec-14 7:55am    
Congratulations on your great recent track record in providing many useful answers here on QA !

In this case, without knowing more from the OP, is this reply of yours really a "solution" ?
Marcin Kozub 4-Dec-14 8:51am    
In this case personally I think that one quick look at examples on that msdn website can give OP very useful hint how to solve his/her problem. I used this site to learn linq by myself.

And thx for a good word, I'm doing my best to help.
amnk.info 4-Dec-14 23:13pm    
thanks i found it from that site
Marcin Kozub 5-Dec-14 6:11am    
You're welcome.
datble.Compute("sum(RATE)", "1=1")); //where rate is a column inside the datatable
 
Share this answer
 
Comments
amnk.info 5-Dec-14 1:36am    
thanks for replying me. your answer also worked.
You haven't provided enough information about what you are trying to do, so with that in mind all I can do is send to you towards an example on the MSDN site.

Sum - Grouped[^]

If this isn't what you are after then please edit your question and provide as much detail as you can, including some code that you have tried etc.
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900