Hi ramco1917,
Please refer below sample.
Database
For this example I have used of Northwind database that you can download using the link given below.
Download Northwind Database
HTML
Total:<asp:Label ID="lblSum" runat="server" />
Code
C#
protected void Page_Load(object sender, EventArgs e)
{
if (!this.IsPostBack)
{
lblSum.Text = Math.Round(subSum().Value, 2).ToString();
}
}
public decimal? subSum()
{
NORTHWINDEntities entities = new NORTHWINDEntities();
try
{
decimal? Result = (from t in entities.Orders.Take(10)
select t.Freight).Sum();
return Result;
}
catch (Exception ex)
{
throw ex;
}
}
VB.Net
Protected Sub Page_Load(ByVal sender As Object, ByVal e As EventArgs) Handles Me.Load
If Not Me.IsPostBack Then
lblSum.Text = Math.Round(subSum().Value, 2).ToString()
End If
End Sub
Public Function subSum() As Decimal?
Dim entities As NORTHWINDEntities = New NORTHWINDEntities()
Try
Dim Result As Decimal? = (From t In entities.Orders.Take(10) Select t.Freight).Sum()
Return Result
Catch ex As Exception
Throw ex
End Try
End Function
Output
Total:635.95