[Last Call] Learn how to a build a cloud-first strategyRegister Now

x
?
Solved

Looping Through a Datarow

Posted on 2009-12-21
3
Medium Priority
?
199 Views
Last Modified: 2012-05-08
Experts,

I'm looping through the DataRow collection of a table and getting each row out one at a time with a For Each loop.  I want to do the same thing with the columns of a DataRow object, but it's not set up that way.  What is the best way to do this?
0
Comment
Question by:NigelRocks
  • 3
3 Comments
 
LVL 21

Accepted Solution

by:
silemone earned 2000 total points
ID: 26096726
why do you need to loop through each column?  its not set up for that because a datatable will always have the same column names for each row...

so you just call it explicitly


row[0]
row["columnName"]
0
 
LVL 21

Assisted Solution

by:silemone
silemone earned 2000 total points
ID: 26096739
if you want to get the column Name because you don't know the name or amount of columns for the table

see this link

http://msdn.microsoft.com/en-us/library/system.data.datacolumn.columnname.aspx
0
 
LVL 21

Assisted Solution

by:silemone
silemone earned 2000 total points
ID: 26096746
code snippet

For Each table in dataSet.Tables
        For Each column in table.Columns
        Console.WriteLine(column.ColumnName)
        Next
    Next
0

Featured Post

Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Introduction While answering a recent question (http://www.experts-exchange.com/Q_27402310.html) in the VB classic zone, I wrote some VB code in the (Office) VBA environment, rather than fire up my older PC.  I didn't post completely correct code o…
Article by: Martin
Here are a few simple, working, games that you can use as-is or as the basis for your own games. Tic-Tac-Toe This is one of the simplest of all games.   The game allows for a choice of who goes first and keeps track of the number of wins for…
Get people started with the process of using Access VBA to control Outlook using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Microsoft Outlook. Using automation, an Access applic…
Get people started with the process of using Access VBA to control Excel using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Excel. Using automation, an Access application can laun…
Suggested Courses
Course of the Month17 days, 21 hours left to enroll

830 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question