troubleshooting Question

Lopp through data table

Avatar of lemarge
lemarge asked on
Programming Languages-OtherC#
1 Comment1 Solution271 ViewsLast Modified:
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.
Project Manager / Technical Lead

Our community of experts have been thoroughly vetted for their expertise and industry experience.

Join our community to see this answer!
Unlock 1 Answer and 1 Comment.
Start Free Trial
Learn from the best

Network and collaborate with thousands of CTOs, CISOs, and IT Pros rooting for you and your success.

Andrew Hancock - VMware vExpert
See if this solution works for you by signing up for a 7 day free trial.
Unlock 1 Answer and 1 Comment.
Try for 7 days

”The time we save is the biggest benefit of E-E to our team. What could take multiple guys 2 hours or more each to find is accessed in around 15 minutes on Experts Exchange.

-Mike Kapnisakis, Warner Bros