Hi,
Here is my code :
For Each row As DataRow In ds.Tables(0).Ro ws
next
How can I get the index of the row being processed ?
Thx 8 10287
Of course I could include a counter in my loop ... but i was wondering
if there is another way
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.goo glegroups.com.. . Hi, Here is my code :
For Each row As DataRow In ds.Tables(0).Ro ws next
How can I get the index of the row being processed ?
Thx
Of course I could include a counter in my loop ... but i was wondering
if there is another way
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
Why?
Cor
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).Ro ws.Count - 1
Dim row As DataRow = ds.Tables(0).Ro ws(index)
...
Next
or
Dim index As Integer = 0
For Each row As DataRow In ds.Tables(0).Ro ws
...
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.goo glegroups.com.. .
| Hi,
| Here is my code :
|
| For Each row As DataRow In ds.Tables(0).Ro ws
| next
|
| How can I get the index of the row being processed ?
|
| Thx
|
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).Ro ws.Count - 1 Dim row As DataRow = ds.Tables(0).Ro ws(index) ... Next
or
Dim index As Integer = 0 For Each row As DataRow In ds.Tables(0).Ro ws ... 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
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******** ******@TK2MSFTN GP14.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).Ro ws.Count - 1
| > Dim row As DataRow = ds.Tables(0).Ro ws(index)
| > ...
| > Next
| >
| > or
| >
| > Dim index As Integer = 0
| > For Each row As DataRow In ds.Tables(0).Ro ws
| > ...
| > 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
|
| This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics |
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 from Equipment where"
" Eqnum = " + "'" + equipLabel.Text + "'"
oda1 = new OleDbDataAdapter(equipSelect, equipConnect)
DataSet ds1 = new DataSet()
|
by: Justin |
last post by:
How do I find the index number of a row inorder to update it?
Thanks, Justin.
|
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 is inside a dataset. One of
the columns is "ID" field. If I want to retrieve the row index of a row with
ID = 10, is there any API which I could use...
|
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 query for the added recorded Index key. Anyone knows what would be the best way to solve this problem
Clearing dataset and refilling it won’t work...
|
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:
DataGridView.Rows(5) <=====> DataSet.Rows(5) .
| |
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 what to do.
Please help me.
Thanx in advanced.
Michel
Here is the error.
Server Error in '/' Application.
|
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,
myTable.Columns.IndexOf("myColumnName")
Thanks.
|
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 of making a case statement
with 26 options, is there a more streamlined way to get an integer between
1-26 translated into one of the letters?
|
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. This functionality works with a fixed set of values in the drop-down (i.e. <option value tags). Any insight would be greatly appreciated.
<INPUT...
|
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main...
|
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that...
| |
by: Hystou |
last post by:
Overview:
Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For...
|
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 protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the...
|
by: agi2029 |
last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then...
|
by: isladogs |
last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM).
In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules.
He will explain when you may want to use classes...
|
by: 6302768590 |
last post by:
Hai team
i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
|
by: muto222 |
last post by:
How can i add a mobile payment intergratation into php mysql website.
| |
by: bsmnconsultancy |
last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating...
| |