473,405 Members | 2,334 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,405 software developers and data experts.

accessing elements in a collection

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

Jul 19 '06 #1
3 1279
Hi,

Its easy,

dt.Rows[0]

Regards,
Tiago Teixeira
su*******@gmail.com 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
Jul 19 '06 #2
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?

Jul 19 '06 #3
How about this: dt.Rows[0]
"su*******@gmail.com" 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

Jul 19 '06 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
by: johkar | last post by:
I have a table, simplified below, which has <col> and <tbody> elements. Is there an easy way using DOM to access the table row length? The number of rows varies as it is generated by an...
8
by: Generic Usenet Account | last post by:
To settle the dispute regarding what happens when an "erase" method is invoked on an STL container (i.e. whether the element is merely removed from the container or whether it also gets deleted in...
6
by: David D. | last post by:
I want to be able to access cells within an HTML table, via computed row number and column number. I was considering using oTableID.children and oTR.children arrays. My question is what...
6
by: Chris Styles | last post by:
Dear All, I've been using some code to verify form data quite happily, but i've recently changed the way my form is structured, and I can't get it to work now. Originally : The form is...
5
by: Jack Addington | last post by:
How do I go about accessing elements of an Arraylist using something other than the index? I have a class that manages a number of subclasses. Those subclasses are stored in an arraylist. The...
1
by: Paul NGPC | last post by:
Hi folks This is a challenging and interesting topic. Need HELP on this, would be good if some tips/techniques can be given for the topic. Using VB.NET client to connect to JavaWebserver....
6
by: mumrah | last post by:
When getting different elements out of an array in JS, i know array.item(0) and array both return the 0th element. My question, will this work in any instance?
19
by: k.karthikit | last post by:
Hello all, In some hidden variable (<input type="hidden" name="hiddenId" value="test" /> ,i stored some value.I accessed the value "test" using var id = document.getElementById( 'hiddenId' );...
9
by: Rainman | last post by:
In my HTML, I have several of the following: <input type='checkbox' name='right' id='right' value='0' /> All are the same except the value is set differently for each one. The reason for the ...
7
by: Chuck Anderson | last post by:
I'm pretty much a JavaScript novice. I'm good at learning by example and changing those examples to suit my needs. That said .... ..... I have some select fields in a form I created for a...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.