Link to home
Start Free TrialLog in
Avatar of lemarge
lemarge

asked on

Lopp through data table

I have a data table and would like to loop through all rows and items on the table.
The code below will not work because var in the inner loop creates error. Do yo have any ideas?
DataTable table = (DataTable)ViewState["CurrentTable"]; // Get the data table.
      foreach (DataRow row in table.Rows) // Loop over the rows.
      {
          Console.WriteLine("--- Row ---"); // Print separator.
          foreach (var item in row.ItemArray) // Loop over the items.
          {
              Console.Write("Item: "); // Print label.
              Console.WriteLine(item); // Invokes ToString abstract method.
          }
      }

Open in new window

ASKER CERTIFIED SOLUTION
Avatar of Darren
Darren
Flag of Ireland image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial