如何循环此数据 [英] How do I loop this data

查看:45
本文介绍了如何循环此数据的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有如下所示的数据集(三列)



没有日期时间

----- ---- ----

200175 01.01.2017 0801

200175 01.01.2017 1740

200178 01.01.2017 0745

200178 01.01.2017 1240

200178 01.01.2017 1320

200178 01.01.2017 1740

200178 02.01.2017 0750

200178 02.01.2017 1230

200178 02.01.2017 1310

200178 02.01.2017 1620



我想首先在选定的日期循环然后第一个员工的两个记录

同样在同一个日期完成给下一个员工

对我来说第二个循环工作但第一个循环仍然在起点

我想要第二个循环也得到更新



我是c#的新手所以希望你们都明白我的错误



有人可以帮我吗



谢谢



Ajith



我尝试过:



I have set of data shown below (three columns)

empno date time
----- ---- ----
200175 01.01.2017 0801
200175 01.01.2017 1740
200178 01.01.2017 0745
200178 01.01.2017 1240
200178 01.01.2017 1320
200178 01.01.2017 1740
200178 02.01.2017 0750
200178 02.01.2017 1230
200178 02.01.2017 1310
200178 02.01.2017 1620

I want to loop first on selected date and then first employee's two records
when finished to next employee on same date likewise
for me second loop worked but first loop still at the start point
I want second loop also get updated

I new to c# so hope you all understand my mistakes

can anybody help me

Thanks

Ajith

What I have tried:

int x=0;
DateTime  dFDate =thistext1;
DateTime  dTDate =thistext2;

for (DateTime x = dFDate; x <= dTDate; x = x.AddDays(1))
{

    dDDate = x;
    duserdata = this.timeattDataSet.data;
    DataRow[] result1 = duserdata.Select("Date = #" + dDDate + "#");

    foreach (DataRow rowsdate in result1)
    {
      if (System.DateTime.Equals(rowsdate["Date"], dDDate))
      {
      string cEmpno = rowsdate["Token_no"].ToString();
      DataRow[] result2 = duserdata.Select("Date = #" + dDDate + "#" + " AND " + " Token_no = " + cEmpno) ;

      foreach (DataRow rowstime in result2)
      {

         // Here I calculate time period
         // this loop work fine

      }
    }
  }
}

推荐答案

我认为它使用SQL查询更有效率,它只检索您感兴趣的记录(特别是如果您有一个大型数据库),例如:

I think it is more efficient to use an SQL query which retrieves only the records you are interested in (especially if you have a large database), example:
SELECT * FROM Orders
WHERE OrderDate BETWEEN #07/04/1996# AND #07/09/1996#;

然后您可以使用sql datareader遍历结果,请参阅此处的示例: [ ^ ]

Then you can use an sql datareader to loop through the results, see example here: [^]


这篇关于如何循环此数据的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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