Lopp through data table

lemarge used Ask the Experts™
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

Watch Question

Do more with

Expert Office
EXPERT OFFICE® is a registered trademark of EXPERTS EXCHANGE®
Senior Software Engineer
Change var to Object



Do more with

Expert Office
Submit tech questions to Ask the Experts™ at any time to receive solutions, advice, and new ideas from leading industry professionals.

Start 7-Day Free Trial