使用C#不使用LINQ:(MM HH)获得数据集的列在总时间格式 [英] Get Total of a column from Dataset in Time Format(HH:MM) using C# without using Linq

查看:117
本文介绍了使用C#不使用LINQ:(MM HH)获得数据集的列在总时间格式的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

有没有办法得到总的数据集中的列不使用LINQ查询?

Is there a way to get the total of a column from a dataset without using a LINQ Query?

CREATE procedure St_Proc_GetUserReportforCurrentDayTask                        
@userID int                        
as                        
    Begin                        
        set NoCount on;                        
        DECLARE @TODAY DATE                          
        SET @TODAY = CONVERT(VARCHAR(10), GETDATE(), 111)                        
        select  CONVERT(VARCHAR,production.CalendarDate,101) + RIGHT (CONVERT(VARCHAR,production.CalendarDate , 100 ) ,7) as Date,                         
        RegionAndProjectInfo.RegionProjectName as Region ,                        
        County.CountyName as County,                        
        WorkType.WorkTypeName as WorkType,                        
        Task.TaskName as Task,            
        Production.VolumeProcessed as 'Volumes Processed',                        
        Production.TimeSpent as 'Duration'                        
        from Production                         
        inner join RegionAndProjectInfo                        
        on                        
        RegionAndProjectInfo.RegionProjectID=Production.RegionProjectID                        
        inner join County                        
        on                         
        County.CountyID=Production.CountyID                        
        inner join WorkType                        
        on                        
        WorkType.WorkTypeID=Production.WorkTypeID                        
        inner join Task                        
        on                        
        Task.TaskID=Production.TaskID                        
        where Production.UserID=@userID and CalendarDate >= @TODAY                        
    End 

从上面的存储过程,我填的数据集。在那之后,我结合这个数据集以网格视图。在数据集中,列持续时间包含在数据HH:MM格式(例如 - 01:00,12:45,02:59,等等)。有没有一种方法,我可以得到总持续时间 HH:从数据本身MM 格式?我不想从数据库中再次查询获得的持续时间 SUM 。我已经张贴了这个问题已经<一个href=\"http://stackoverflow.com/questions/11543423/get-total-in-hhmm-format-from-the-dataset\">Here但解决的办法是使用LINQ查询,我不想使用。

From the above stored procedure, I am filling a Dataset. After that, I am binding this Dataset to a grid view. In the dataset, the column Duration contains data in an HH:MM Format (example - 01:00, 12:45, 02:59, etc). Is there a way that I can get the total of Duration in HH:MM format from the dataset itself? I don't want to query again from the database to get the SUM of Duration. I had posted this question already Here but the solution was to use a LINQ query, which I dont want to use.

推荐答案

我很好奇,为什么你不希望使用Linq,但我离题...

I'm curious why you don't want to use Linq, but I digress...

下面是一个使用循环一个未LINQ-Y版本:

Here's an un-linq-y version using loops:

double total = 0;
foreach(DataRow r in dataSet.Tables[0].Rows)
{

    var DurHour = r["Duration"].ToString().Split(':')[0];
    var DurMinute = r["Duration"].ToString().Split(':')[1];
    TimeSpan ts = new TimeSpan(int.Parse(DurHour), int.Parse(DurMinute), 0);
    total += ts.TotalMinutes;
}

Console.WriteLine("Total time in minutes: {0}", total);

这篇关于使用C#不使用LINQ:(MM HH)获得数据集的列在总时间格式的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆