473,471 Members | 1,883 Online
Bytes | Software Development & Data Engineering Community
Create Post

Home Posts Topics Members FAQ

Iterate collections

Hi there,

How can I iterate through collections starting not from the first item but
from an offset?
I need to check if a dataset contains records that have some field values
that can conflict with some other records. So my code would be like the
following:

MyDataSet copyDataSet = new MyDataSet();
copyDataSet = myDataSet.Copy();
foreach(DataRow row in myDataSet.MyTable.Rows)
foreach(DataRow copyRow in copyDataSet.MyTable.Rows)
Do the records validation
the problem with this approach is that I will do checks twice, I need to
start iterating the copyDataSet.MyTable.Rows not from the first row but from
the row of myDataSet.MyTable.Rows + 1.

How can I achieve this?

Thanks
Antonio

Nov 17 '05 #1
4 1399
use a for loop

for(int x = 10; x < ds.Tables[0].Rows.Count; x++){
for(int y = 5; y < ds.Tables[0].Columns.Count; y++){
ds.Tables[0].Rows[x][y] == . . .
}
}

"Antonio Budano" wrote:
Hi there,

How can I iterate through collections starting not from the first item but
from an offset?
I need to check if a dataset contains records that have some field values
that can conflict with some other records. So my code would be like the
following:

MyDataSet copyDataSet = new MyDataSet();
copyDataSet = myDataSet.Copy();
foreach(DataRow row in myDataSet.MyTable.Rows)
foreach(DataRow copyRow in copyDataSet.MyTable.Rows)
Do the records validation
the problem with this approach is that I will do checks twice, I need to
start iterating the copyDataSet.MyTable.Rows not from the first row but from
the row of myDataSet.MyTable.Rows + 1.

How can I achieve this?

Thanks
Antonio

Nov 17 '05 #2
Joe
Hi Antonio,

How about something like this?

int rowIdx = 0;
foreach (DataRow row in myDataSet.MyTable.Rows)
{
for (int r = rowIdx; r < copyDataSet.MyTable.Rows.Count; r++)
{
DataRow copiedRow = copyDataSet.MyTable.Rows[rowIdx];
// Do what you need
}
rowIdx ++;
}

-Joe

"Antonio Budano" <antonio.budano_REMOVE_THIS_@_REMOVE_THIS_poste.it > wrote
in message news:Oe*************@TK2MSFTNGP09.phx.gbl...
Hi there,

How can I iterate through collections starting not from the first item but
from an offset?
I need to check if a dataset contains records that have some field values
that can conflict with some other records. So my code would be like the
following:

MyDataSet copyDataSet = new MyDataSet();
copyDataSet = myDataSet.Copy();
foreach(DataRow row in myDataSet.MyTable.Rows)
foreach(DataRow copyRow in copyDataSet.MyTable.Rows)
Do the records validation
the problem with this approach is that I will do checks twice, I need to
start iterating the copyDataSet.MyTable.Rows not from the first row but
from the row of myDataSet.MyTable.Rows + 1.

How can I achieve this?

Thanks
Antonio

Nov 17 '05 #3
Why did I post this stupid question?
It is too late here in Italy to continue to work, I am going to bed.

Thank you for your answer, also to Eric.
Antonio
Nov 17 '05 #4
generally, don't like to mix methods for rolling through a
collection, so use a for in both cases, or neither...

how about...
DataRow row, copy;
for (int i=0; i < myDataSet.MyTable.Rows.Count; i++) {
row = myDataSet.MyTable.Rows[i];
for (int j=i+1; j<copyDataSet.MyTable.Rows.Count; j++) {
copy = copyDataSet.MyTable.Rows[j];
//do your stuff...
}
}

depending on the actions being taken, a DataView is probably
a better option in any case...

Joe wrote:
Hi Antonio,

How about something like this?

int rowIdx = 0;
foreach (DataRow row in myDataSet.MyTable.Rows)
{
for (int r = rowIdx; r < copyDataSet.MyTable.Rows.Count; r++)
{
DataRow copiedRow = copyDataSet.MyTable.Rows[rowIdx];
// Do what you need
}
rowIdx ++;
}

-Joe

"Antonio Budano" <antonio.budano_REMOVE_THIS_@_REMOVE_THIS_poste.it > wrote
in message news:Oe*************@TK2MSFTNGP09.phx.gbl...
Hi there,

How can I iterate through collections starting not from the first item but
from an offset?
I need to check if a dataset contains records that have some field values
that can conflict with some other records. So my code would be like the
following:

MyDataSet copyDataSet = new MyDataSet();
copyDataSet = myDataSet.Copy();
foreach(DataRow row in myDataSet.MyTable.Rows)
foreach(DataRow copyRow in copyDataSet.MyTable.Rows)
Do the records validation
the problem with this approach is that I will do checks twice, I need to
start iterating the copyDataSet.MyTable.Rows not from the first row but
from the row of myDataSet.MyTable.Rows + 1.

How can I achieve this?


--
Michael J. Ryan - tracker1(at)theroughnecks(dot)net - www.theroughnecks.net
icq: 4935386 - AIM/AOL: azTracker1 - Y!: azTracker1 - MSN/Win: (email)
Nov 17 '05 #5

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

Similar topics

2
by: njp | last post by:
BlankHi, How do I create a tightly coupled Object 1 such that when I update it in one collection, it is simultaneously and automatically updated in other collections? The collections are defined...
2
by: James Doran | last post by:
Hello, I'd like to iterate through each Page of my ASP.NET project from within a Custom web control and access the Page.Controls collection. I've tried using Reflection on the web project...
11
by: Boni | last post by:
Dear all, following code iterates thru the hash table. Dim _Enumerator As IDictionaryEnumerator = _myhashtable.GetEnumerator While _Enumerator.MoveNext() ....
5
by: Simon | last post by:
Hi all, I am writing a windows application using vb.net on the 1.1 framework. We have in the application, some strongly typed collections that have been written as classes that do not inherit...
4
by: nhmark64 | last post by:
Hi, Does System.Collections.Generic.Queue not have a Synchronized method because it is already in effect synchronized, or is the Synchronized functionality missing from...
4
by: Adam Clauss | last post by:
I ran into a problem a while back when attempting to convert existing .NET 1.1 based code to .NET 2.0 using Generic collections rather than Hashtable, ArrayList, etc. I ran into an issue because...
2
by: Fred Heida | last post by:
Hi, i'm trying to (using managed C++) implment the IEnumerable<Tinterface on my class.. but have a problem with the 2 GetEnumerator method required.... what i have done is... ...
4
by: Sid Price | last post by:
Hello, I have a class of objects (Device) that are managed by another object (Devices) with a collection class (DeviceCollection) inherited from Collections.Hashtable. Each of the Device objects...
0
by: engblom | last post by:
I'm trying to get the check items text from a checkedlistbox? This code below results in: List that this enumerator is bound to has been modified. An enumerator can only be used if the list does...
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
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,...
1
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...
0
agi2029
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,...
1
isladogs
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...
0
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
0
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
0
muto222
php
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.