PC Review


Reply
Thread Tools Rate Thread

accessing elements in a collection

 
 
suspended@gmail.com
Guest
Posts: n/a
 
      19th Jul 2006
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

 
Reply With Quote
 
 
 
 
teixeira1985@gmail.com
Guest
Posts: n/a
 
      19th Jul 2006
Hi,

Its easy,

dt.Rows[0]

Regards,
Tiago Teixeira


(E-Mail Removed) wrote:
> 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


 
Reply With Quote
 
Dan Dorey
Guest
Posts: n/a
 
      19th Jul 2006
for (int i = 0; i < dt.Rows.Count; i++)
{
// use dt.Rows[i] to do whatever you want...
dt.Rows[i] = null;
}

Is a for loop ok?

 
Reply With Quote
 
=?Utf-8?B?TWluaS1Ub29scyBUaW1t?=
Guest
Posts: n/a
 
      19th Jul 2006
How about this: dt.Rows[0]


"(E-Mail Removed)" wrote:

> 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?


--
Timm Martin
Mini-Tools
..NET Components and Windows Software
http://www.mini-tools.com

 
Reply With Quote
 
 
 
Reply

Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Re: Finding elements in a collection Chip Pearson Microsoft Excel Programming 1 11th Jan 2007 11:38 PM
Re: Finding elements in a collection paul.robinson@it-tallaght.ie Microsoft Excel Programming 0 11th Jan 2007 04:52 PM
Arrays vs collection ? more than 100 elements =?Utf-8?B?dmlrcmFudGNh?= Microsoft Dot NET Framework 1 30th Sep 2004 09:34 PM
Access collection elements with the Dot (.) operator Ana Lindt Microsoft C# .NET 1 4th Jun 2004 03:44 PM
Bug: form.elements collection =?Utf-8?B?Z2xpc3Rhcg==?= Windows XP Internet Explorer 0 9th May 2004 04:46 AM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 08:20 PM.