How to loop through the fields (columns) of a dataset's table row

  • Thread starter Thread starter moondaddy
  • Start date Start date
M

moondaddy

How can I loop through all the fields in a strongly typed dataset's table
row and retrieve the name and value?

Thanks.
 
Each column is indexed.
x = ds.tables(0).rows(n).(intCol)
or
x = ds.tables(0).rows(n).item(intCol)

hth

--
____________________________________
William (Bill) Vaughn
Author, Mentor, Consultant
Microsoft MVP
www.betav.com
Please reply only to the newsgroup so that others can benefit.
This posting is provided "AS IS" with no warranties, and confers no rights.
__________________________________
 
moondaddy said:
How can I loop through all the fields in a strongly typed dataset's table
row and retrieve the name and value?


DataTable dt=...;
foreach (DataColumn c in dt.Columns)
{
Console.WriteLine(c.ColumnName + " " + dt[c]);
}

David
 
David Browne said:
moondaddy said:
How can I loop through all the fields in a strongly typed dataset's table
row and retrieve the name and value?


DataTable dt=...;
foreach (DataColumn c in dt.Columns)
{
Console.WriteLine(c.ColumnName + " " + dt[c]);
}

sb
DataTable dt=...;

foreach (DataRow r in dt.Rows)
foreach (DataColumn c in dt.Columns)
{
Console.WriteLine(c.ColumnName + " " + r[c]);
}

David
 
Thanks to all who answered this post. each answer is helpful and I'll use a
little from all! :)
 
Back
Top