Avatar of Cartillo
CartilloFlag for Malaysia

asked on 

Add total automatically

Hi Experts,

I need Experts help. How to add automatically total sum of data (time) from column TimeIN and TimeOUT at column Total_Duration. At present the data was not automatically count at Total_Duration column. Hope Experts will help create this feature.
Imports MyCompany.Data
Imports System
Imports System.Collections.Generic
Imports System.Data
Imports System.Linq
Imports System.Text.RegularExpressions
Imports System.Web

Namespace Rules
    
    Partial Public Class DataBusinessRules
        Inherits MyCompany.Rules.SharedBusinessRules
        
        <RowBuilder("Data", RowKind.New)>  _
        Public Sub BuildNewData()
            UpdateFieldValue("Total_Duration", "(datediff(HOUR,[TimeIN],[TimeOUT]))")
        End Sub
    End Class
End Namespace

Open in new window

VB ScriptASP.NET

Avatar of undefined
Last Comment
Cartillo
Avatar of Tom Beck
Tom Beck
Flag of United States of America image

Is this a Sql database?
What is the data type for Time_Duration?
Avatar of Cartillo
Cartillo
Flag of Malaysia image

ASKER

Hi,

Yes, indeed. I'm using "time(7)" as data type at Time_Duration column.
Avatar of Tom Beck
Tom Beck
Flag of United States of America image

Confused.

Are you trying to figure out what the new time would be if the interval between TimeIN and TimeOUT were added to it? Part of the confusion comes from the difference in accuracy between the value returned from DateDiff (hours as integer) and the use of time (7) data type for Time_Duration which is something like a millionth of a second accuracy.

If you just want to use Time_Duration as a running total of hours, why not make it an Integer and just add the result of DateDiff to it.
Avatar of Cartillo
Cartillo
Flag of Malaysia image

ASKER

Hi tommyBoy,

I've modify the total duration type as "int" but the return value not showing total duration of it. Attached the script that being used. Hope I have followed the right steps.
Imports MyCompany.Data
Imports System
Imports System.Collections.Generic
Imports System.Data
Imports System.Linq
Imports System.Text.RegularExpressions
Imports System.Web

Namespace Rules
    
    Partial Public Class timeBusinessRules
        Inherits MyCompany.Rules.SharedBusinessRules
        
        <ControllerAction("time", "Calculate", "Total_Duration")>  _
        Public Sub Calculatetime(ByVal time_ID As Nullable(Of Integer), ByVal [date] As Nullable(Of DateTime), ByVal timeIN As Nullable(Of System.TimeSpan), ByVal timeOUT As Nullable(Of System.TimeSpan), ByVal total_Duration As Nullable(Of Integer))
            UpdateFieldValue("Total_Duration", "(datediff(HOUR,[TimeIN],[TimeOUT]))")

        End Sub
    End Class
End Namespace

Open in new window

ASKER CERTIFIED SOLUTION
Avatar of Tom Beck
Tom Beck
Flag of United States of America image

Blurred text
THIS SOLUTION IS ONLY AVAILABLE TO MEMBERS.
View this solution by signing up for a free trial.
Members can start a 7-Day free trial and enjoy unlimited access to the platform.
See Pricing Options
Start Free Trial
Avatar of Cartillo
Cartillo
Flag of Malaysia image

ASKER

Hi,

Thanks for the help
ASP.NET
ASP.NET

The successor to Active Server Pages, ASP.NET websites utilize the .NET framework to produce dynamic, data and content-driven web applications and services. ASP.NET code can be written using any .NET supported language. As of 2009, ASP.NET can also apply the Model-View-Controller (MVC) pattern to web applications

128K
Questions
--
Followers
--
Top Experts
Get a personalized solution from industry experts
Ask the experts
Read over 600 more reviews

TRUSTED BY

IBM logoIntel logoMicrosoft logoUbisoft logoSAP logo
Qualcomm logoCitrix Systems logoWorkday logoErnst & Young logo
High performer badgeUsers love us badge
LinkedIn logoFacebook logoX logoInstagram logoTikTok logoYouTube logo