How to iterate through a DataTable in C#

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

I have an InMemory DataTable that I used as a datasource for my grid.

I need to know how to interate through it.

The onlione books say there exist a property called item on the DataRow but
my C# intellisense doesn't show this.

Here is the code so far.


foreach(DataRow dr in dt.Rows)
{
//how do I iterate through the columns of each row in my DataTale (dt)?
{


Thanks

Tom
 
Hi Tom,
There are a number of ways to loop through the Columns, one being:

DataTable tbl = new DataTable();
foreach (DataRow row in tbl.Rows)
{
foreach (DataColumn col in tbl.Columns)
{
object cellData = row[col];
}
}

Cheers,
Steve Goodyear
 
Back
Top