0

Here is my code first and then ill explain what im doing.

ds.Dispose();
             ds = new DataSet();
             db = new DBconnect();
             Co = new Cards('S', Global.GlobalCompanyID).SetSql();
             ds = db.GetDataSet(Co);
             dt = ds.Tables[0];
             dr = dt.Rows[0];


             Out = dr[1].ToString();
                

             if (Out != "")
             {

                 Time tm = new Time("");
                    
                   // For each row, print the values of each column.
                 foreach(DataRow row in dt.Rows)
                 {
                        
                     Out = dr[1].ToString();
                        
                        
                            
                         In = dr[0].ToString();
                  }
              }

Im trying to get time in (IN) and time out (OUT) from my Database.
the problem is when it loops through it pulls the same record again and again.
If there are three records it would pull. it pulls the first one three times.
I need it to pull the proper records.

2
Contributors
1
Reply
2
Views
7 Years
Discussion Span
Last Post by Mitja Bonca
0

You have to bind to a different variable in the foreach loop, like:

 foreach(DataRow row in dt.Rows)
 {

     Out = row[1].ToString();
     In =  row[0].ToString();
  }

Edited by Reverend Jim: Fixed formatting

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.