473,386 Members | 1,598 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,386 software developers and data experts.

getting row index of dataset

Sam
Hi,
Here is my code :

For Each row As DataRow In ds.Tables(0).Rows
next

How can I get the index of the row being processed ?

Thx

Nov 21 '05 #1
8 10268
Sam
Of course I could include a counter in my loop ... but i was wondering
if there is another way

Nov 21 '05 #2
If you use an indexed loop instead of a For Each loop then you will have the
index at your fingertips.
"Sam" <sa**************@voila.fr> wrote in message
news:11**********************@f14g2000cwb.googlegr oups.com...
Hi,
Here is my code :

For Each row As DataRow In ds.Tables(0).Rows
next

How can I get the index of the row being processed ?

Thx

Nov 21 '05 #3
Sam
Of course I could include a counter in my loop ... but i was wondering
if there is another way

Nov 21 '05 #4
Sam
sorry I was writing my message while you were posting yours. I wasn't
meant to be rude :)
So ok, i'll use a counter instead
thx

Nov 21 '05 #5
> Of course I could include a counter in my loop ... but i was wondering
if there is another way


Why?

Cor
Nov 21 '05 #6
Sam,
In addition to using an indexed For loop. You can simply increment a counter
with a For Each.

For index As Integer = 0 to ds.Tables(0).Rows.Count - 1
Dim row As DataRow = ds.Tables(0).Rows(index)
...
Next

or

Dim index As Integer = 0
For Each row As DataRow In ds.Tables(0).Rows
...
index += 1
Next

Either works, performance may vary based on the specific collection. I
normally use the second as it seems cleaner.

Hope this helps
Jay
"Sam" <sa**************@voila.fr> wrote in message
news:11**********************@f14g2000cwb.googlegr oups.com...
| Hi,
| Here is my code :
|
| For Each row As DataRow In ds.Tables(0).Rows
| next
|
| How can I get the index of the row being processed ?
|
| Thx
|
Nov 21 '05 #7
Jay,

In addition to using an indexed For loop. You can simply increment a
counter
with a For Each.

For index As Integer = 0 to ds.Tables(0).Rows.Count - 1
Dim row As DataRow = ds.Tables(0).Rows(index)
...
Next

or

Dim index As Integer = 0
For Each row As DataRow In ds.Tables(0).Rows
...
index += 1
Next

Either works, performance may vary based on the specific collection. I
normally use the second as it seems cleaner.

So you see how personal preference can be different, for me is that with the
first.

(Maybe because I am with the second never sure that there is not used a kind
of dictionary index, what does in the first case not matter, I hope this
describes what I want to say with that. I don't believe that that is done
here by the way)

That leads me to use consequently to use the first when I need an index. Can
be a crazy feeling by the way.

Cor
Nov 21 '05 #8
Cor,
| (Maybe because I am with the second never sure that there is not used a
kind
| of dictionary index, what does in the first case not matter, I hope this
| describes what I want to say with that. I don't believe that is done
| here by the way)
If the first does not have an "index" to use performance can greatly matter!
For example if the "list" is based on a linked list, the performance of the
first can be horrific as you need to recount each element each time you call
the Item (indexer) property...

Also as you suggest, For index will not work with a hashtable (dictionary).
Why have an "oddball solution" and use For index for some loops & For each
for others. Hence I normally use For each for all loops...

Just a thought
Jay
"Cor Ligthert" <no************@planet.nl> wrote in message
news:u3**************@TK2MSFTNGP14.phx.gbl...
| Jay,
|
|
| > In addition to using an indexed For loop. You can simply increment a
| > counter
| > with a For Each.
| >
| > For index As Integer = 0 to ds.Tables(0).Rows.Count - 1
| > Dim row As DataRow = ds.Tables(0).Rows(index)
| > ...
| > Next
| >
| > or
| >
| > Dim index As Integer = 0
| > For Each row As DataRow In ds.Tables(0).Rows
| > ...
| > index += 1
| > Next
| >
| > Either works, performance may vary based on the specific collection. I
| > normally use the second as it seems cleaner.
| >
| So you see how personal preference can be different, for me is that with
the
| first.
|
| (Maybe because I am with the second never sure that there is not used a
kind
| of dictionary index, what does in the first case not matter, I hope this
| describes what I want to say with that. I don't believe that that is done
| here by the way)
|
| That leads me to use consequently to use the first when I need an index.
Can
| be a crazy feeling by the way.
|
| Cor
|
|
Nov 21 '05 #9

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

Similar topics

1
by: Dave Bailey | last post by:
When I run the following code public DataView CreateEquipmentDataSource( string equipConnect = "Provider=\"MSDAORA.1\";" + GetConnectionString() + "" string equipSelect = "Select Description...
2
by: Justin | last post by:
How do I find the index number of a row inorder to update it? Thanks, Justin.
1
by: Diffident | last post by:
Hello All, Was wondering if we could retrieve the index of a particular row from a dataset's table based on the filter criteria for the row? For example, I have 4 rows in my datatable which...
0
by: Lisa Jones | last post by:
Hi Has anyone see this problem in ADO.Net when deleting a record (assuming that the table has identity increment Index) result in getting wrong index key if right after adding the record the table...
7
by: Robert Koller | last post by:
Hello i have this problem: In a DataGridView the user work with data from a DataSet. on Start the row index from datagridview is the same as the row index from the dataset. Also: ...
1
by: Michel Moreno | last post by:
Hi everybody, i would like to query the Index Catalog, for a site, as describe in the article: http://support.microsoft.com/default.aspx?scid=kb;en-us;820105 But i'm having an error, I don't know...
3
by: Programatix | last post by:
Hi. I'm using a strongly typed dataset and I would like to get the index number of a column from a datarow. Is that possible? I would like to avoid using expression like this, ...
4
by: darrel | last post by:
I can grab a random number in vb.net like this: Dim RandomClass As New Random Dim RandomNumber As Integer RandomNumber = RandomClass.Next(1, 26) However, what I want is a random number. Short...
5
by: jdzemke | last post by:
I am getting 'options' is null or not an object using when using a dynamic dataset with a dropdown list in an html form. I am filling-in a text field and filtering the values in the drop-down. ...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
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?
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
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...

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.