Click here to Skip to main content
15,893,923 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
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

      }
    }
  }
}
Posted
Updated 2-Jun-17 7:47am
Comments
Perić Željko 3-Jun-17 14:05pm    
I think that You should sort data first by Date-Time, than by Employee in prefered sort order. After that You do not need multiple looping trough data, just read sorted data succesively.

1 solution

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:
SQL
SELECT * FROM Orders
WHERE OrderDate BETWEEN #07/04/1996# AND #07/09/1996#;
Then you can use an sql datareader to loop through the results, see example here: [^]
 
Share this answer
 
Comments
Member 12931315 2-Jun-17 16:13pm    
Thanks, but I am using dataset rows, is there reader function in rows

Ajith
RickZeeland 2-Jun-17 16:18pm    
See the answer here: https://www.codeproject.com/Answers/1189436/How-to-move-to-next-row-in-while-loop#answer1

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900