954,514 Members — Technology Publication meets Social Media
Username:
Password:
Lost login information?
Have something to say? Contribute New Article Reply to this Article

Foreach

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.

NH1
Light Poster
43 posts since Apr 2010
Reputation Points: 10
Solved Threads: 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();
}

Mitja Bonca
Nearly a Posting Maven
2,485 posts since May 2009
Reputation Points: 641
Solved Threads: 474
 

This article has been dead for over three months

Post: Markdown Syntax: Formatting Help
You
View similar articles that have also been tagged: