472,330 Members | 1,390 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 472,330 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 10180
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\";" +...
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? ...
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...
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...
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:...
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...
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)...
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...
0
by: tammygombez | last post by:
Hey fellow JavaFX developers, I'm currently working on a project that involves using a ComboBox in JavaFX, and I've run into a bit of an issue....
0
by: concettolabs | last post by:
In today's business world, businesses are increasingly turning to PowerApps to develop custom business applications. PowerApps is a powerful tool...
0
better678
by: better678 | last post by:
Question: Discuss your understanding of the Java platform. Is the statement "Java is interpreted" correct? Answer: Java is an object-oriented...
0
by: CD Tom | last post by:
This happens in runtime 2013 and 2016. When a report is run and then closed a toolbar shows up and the only way to get it to go away is to right...
0
by: CD Tom | last post by:
This only shows up in access runtime. When a user select a report from my report menu when they close the report they get a menu I've called Add-ins...
0
by: Naresh1 | last post by:
What is WebLogic Admin Training? WebLogic Admin Training is a specialized program designed to equip individuals with the skills and knowledge...
0
jalbright99669
by: jalbright99669 | last post by:
Am having a bit of a time with URL Rewrite. I need to incorporate http to https redirect with a reverse proxy. I have the URL Rewrite rules made...
0
by: antdb | last post by:
Ⅰ. Advantage of AntDB: hyper-convergence + streaming processing engine In the overall architecture, a new "hyper-convergence" concept was...
2
by: Matthew3360 | last post by:
Hi, I have a python app that i want to be able to get variables from a php page on my webserver. My python app is on my computer. How would I make it...

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.