Datatable foreach

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • lizarebk
    New Member
    • May 2010
    • 1

    Datatable foreach

    Hi All,

    I'm manipulating data from a datasource. So far I have the connection,
    the data in a datatable and bind it to the BindingSource.

    Now I'm trying to do a loop with the following staments using foreach loop.

    DateTime start = Convert.ToDateT ime(table.Rows[0]["time_from"]);
    DateTime end= Convert.ToDateT ime(table.Rows[0]["time_to"]);
    TimeSpan diff = end.Subtract(st art);

    I just want to loop over all the rows from the columns "time_from" and "time_to"

    Any suggestion?

    Thanks in advance!
  • hype261
    New Member
    • Apr 2010
    • 207

    #2
    Originally posted by lizarebk
    Hi All,

    I'm manipulating data from a datasource. So far I have the connection,
    the data in a datatable and bind it to the BindingSource.

    Now I'm trying to do a loop with the following staments using foreach loop.

    DateTime start = Convert.ToDateT ime(table.Rows[0]["time_from"]);
    DateTime end= Convert.ToDateT ime(table.Rows[0]["time_to"]);
    TimeSpan diff = end.Subtract(st art);

    I just want to loop over all the rows from the columns "time_from" and "time_to"

    Any suggestion?

    Thanks in advance!
    simple google search turned up

    foreach (DataRow row in table.Rows) // Loop over the rows.
    {
    }

    Comment

    Working...