|
web
newsgroups
|
|||||||||||||||||||||||
|
|||||||||||||||||||||||
getting row index of datasetHi,
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 If you use an indexed loop instead of a For Each loop then you will have the
index at your fingertips. Show quoteHide quote "Sam" <samuel.berthe***@voila.fr> wrote in message news:1112872090.649286.291220@f14g2000cwb.googlegroups.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 > 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 Of course I could include a counter in my loop ... but i was wondering
if there is another way > Of course I could include a counter in my loop ... but i was wondering Why?> if there is another way Cor Of course I could include a counter in my loop ... but i was wondering
if there is another way 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 Show quoteHide quote "Sam" <samuel.berthe***@voila.fr> wrote in message news:1112872090.649286.291220@f14g2000cwb.googlegroups.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 | Jay,
Show quoteHide quote > In addition to using an indexed For loop. You can simply increment a So you see how personal preference can be different, for me is that with the > 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. > 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 Cor,
| (Maybe because I am with the second never sure that there is not used a If the first does not have an "index" to use performance can greatly matter! 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) 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 Show quoteHide quote "Cor Ligthert" <notmyfirstn***@planet.nl> wrote in message news:u3zpiPGPFHA.3408@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 | |
Is synclock needed in DLL?
2 easy questions How to convert hex to string? Difference between Trim function and Trim member Howto: use mutliple languages C++ in VB.net translation from c# How to get form design view back? sending string thru TCP/IP Can I pass value from VB form to VBS? SharpZipLib & Blocked File |
|||||||||||||||||||||||