accessing elements in a collection

S

suspended

I use foreach loop to access rows in a datatable like this:

DataTable dt;

foreach ( DataRow dr in dt )
{
// do something with dr
}

I want to access the first row in the DataTable without using foreach
loop. How can I do it?

Thanks.
Jess
 
D

Dan Dorey

for (int i = 0; i < dt.Rows.Count; i++)
{
// use dt.Rows to do whatever you want...
dt.Rows = null;
}

Is a for loop ok?
 
G

Guest

How about this: dt.Rows[0]


I use foreach loop to access rows in a datatable like this:

DataTable dt;

foreach ( DataRow dr in dt )
{
// do something with dr
}

I want to access the first row in the DataTable without using foreach
loop. How can I do it?
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top