0

i am having a DataTable called dtTest. i just need to select columns from the C# Datatable using Linq concepts

Data Table Name is DtTest.

Example : DtTest Contains the following data's,

enter image description here

i want the result as below, that is i need the SUM of Qty and Amount columns based on group INO...

enter image description here Can anyone Please help me to solve this....

4

1 回答 1

3
DtTest
.AsEnumerable()
.GroupBy
(
   x=>
   new
   {
       BNO = x.Field<int>("BNO"),
       INO = x.Field<int>("INO"),
       Desp = x.Field<string>("Desp"),
       Rate= x.Field<decimal>("Rate")
   }
)
.Select
(
   x=>
   new 
   {
      x.Key.BNO,
      x.Key.INO,
      x.Key.Desp,
      Qty = x.Sum(z=>z.Field<int>("Qty")),
      x.Key.Rate,
      Amount = x.Sum(z=>z.Field<decimal>("Amount"))
   }
);
于 2013-08-02T11:43:33.400 回答