I have a datagrid that display time sheet information for a requested time
period. In this display a user might have 6 Line Items of activity to
display each with its own hours worked column.
I need to add up all of these hours columns to present a total hours
worked on the bottom of the datagrid.
I found a function but can't seem to get it to work:
Dim dstHours as DataSet
Sub BindMyDataGrid()
Dim strConn as string ="server=nt5;database=plot;uid=sa;pwd="
Dim Conn as new SQLconnection(strConn)
Conn.Open()
Dim strSQL = "SELECT LIEF_tbl.ID, Line_Item.LI_ID AS LineItem,
Component.Component AS Component, Activity.Abbrev AS Activity,
LIEF_tbl.Comments, LIEF_tbl.Hours FROM LIEF_tbl INNER JOIN Line_Item ON
LIEF_tbl.LineItem = Line_Item.ID INNER JOIN Component ON
LIEF_tbl.Component = Component.ID INNER JOIN Activity ON LIEF_tbl.Activity
= Activity.ID Where uid='" & lblUID.Text & "' AND wed= '" &
lblSelectedItem.Text & "'"
Dim Cmd7 as New SQLCommand(strSQL,Conn)
MyDataGrid.DataSource = cmd7.ExecuteReader()
MyDataGrid.DataBind()
End Sub
Function HoursTotal() As String
Dim dtblLief As DataTable
Dim intSumTotal As Integer
dtblLief = dstHours.Tables( "Lief_tbl")
intSumTotal = dtblLief.Compute( "Sum( Hours )", Nothing )
Return intSumTotal.ToString()
End Function
I make a call for the total through the use of a label:
<asp:Label Text='<%# HoursTotal() %>' Runat="server" />
Can anyone point me in the right direction or offer some assistance in
discovering how to sum up columns in asp.net?
Thanks in advance.
Sincerely,
Tim