jezz jezz - 1 year ago 181 Question


This is code that returns list of data from Splatt Table.

Public Function GetListofProduct(ByVal pCOde As String, ByVal date1 As DateTime, ByVal date2 As DateTime) As List(Of Splatt)
Return (From e As Splatt In TradingCTX.Splatts Where e.plCode.Contains(pCOde) And (e.plDate = date1 Or e.plDate = date2)).ToList
End Function

I really need help about getting the sum of the price and transfer it to another gridview.IMAGE 1

Answer Source

Instead of writing the Linq the way you are try like this. This will give you the sum, but you can also return your list by calling ToList() instead of Sum. You can also use Average.

Dim sum As Double = TradingCTX.Splatts.Where(Function(e) e.plCode.Contains(pCOde) And (e.plDate = date1 Or e.plDate = date2)).Sum(Function(e) e.Charges)

You could keep your Linq and just change your ToList() to .Sum(Function(e) e.Charges) where e.Charges is the name of the field you want to sum.

Please explain your difficulties getting the sum value to another table.

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download