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?
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.
}
}
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.