LINQ query to sum Price values stored in datatable

Hi Team,

I need a help where I’m currently dealing with datatables and I have one column named Price and wanted sum up the values in it.

Please help

@Nisha_K21,

Try this LINQ

dbltotalPrice  = dt.AsEnumerable().Sum(Function(row) Convert.ToDouble(row("Price")))

1 Like

Hi @Nisha_K21 ,

Assuming column Price is of the type double

totalPrice = yourDataTable.AsEnumerable().Sum(Function(row) row.Field(Of Double)("Price"))

Explanation

  • yourDataTable: Replace this with the name of your DataTable variable.
  • row.Field(Of Double)("Price"): Accesses each value in the "Price" column as a Double.
  • totalPrice: This should be a variable of type Double to store the sum.
1 Like

Thank you @ashokkarale and @Manisha_Ravindra

This topic was automatically closed 3 days after the last reply. New replies are no longer allowed.