c# - Query Datatable -


i have datatable looks this:

id value 123 4.0 123 5.0 234 1.0 345 2.0 345 3.0 

i want end (probably new datatable) contains sum of values grouped id this:

id sumofvalue 123 9.0 234 1.0 345 5.0 

here code,

var query = row in dtable.asenumerable() group row row.field<double>("item_no") grp orderby grp.key select new {     item_no = grp.key,     sum = grp.sum(r = r.field<double>("item_stock")) }; 

i getting error r undefined, not able add these values in new datatable.

does know how write this?

thanks.

i believe not specifying operation correctly. try this:

var query = row in dtable.asenumerable()                     group row row.field<double>("item_no") grp                     orderby grp.key                     select new                     {                         item_no = grp.key,                         sum = grp.sum(r => r.field<double>("item_stock"))                     }; 

the difference r => r.field instead of r = r.field.


Comments

Popular posts from this blog

php - What is the difference between $_SERVER['PATH_INFO'] and $_SERVER['ORIG_PATH_INFO']? -

fortran - Function return type mismatch -

queue - mq_receive: message too long -