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

Looping within a Loop

I'm having an issue with an inner loop.

Here's the basic Code:

For each......{

//Do code here

//start other loop
For each....{
...}
}

Everything works 100% when I step through the project, however when I break
during the inner loop, and either:
1)Encounter an error
-or-
2)Stop the debugger

It will continue with all iterations of the 1st loop... and not touch the
2nd loop anymore. meaning running through 1000+ rows in a datatable and add
them to an online DB.

Has anyone dealt with an issue like this? I'm working on sensitive
information and this issue is causing big problems.

Thanks!

/RT

Nov 16 '05 #1
4 1908
Can you post more code details please, so that I can help
Thanks

"Ryan Ternier" <rt******@icompasstech.com> wrote in message news:<uE**************@TK2MSFTNGP11.phx.gbl>...
I'm having an issue with an inner loop.

Here's the basic Code:

For each......{

//Do code here

//start other loop
For each....{
...}
}

Everything works 100% when I step through the project, however when I break
during the inner loop, and either:
1)Encounter an error
-or-
2)Stop the debugger

It will continue with all iterations of the 1st loop... and not touch the
2nd loop anymore. meaning running through 1000+ rows in a datatable and add
them to an online DB.

Has anyone dealt with an issue like this? I'm working on sensitive
information and this issue is causing big problems.

Thanks!

/RT

Nov 16 '05 #2
....so the inner stop condition has been met...but what does that look like?
show more code please
Nov 16 '05 #3
Hi ,

With out further code it's impossible to know what is going on.

My guess is that the inner condition is not dependand of the outer loop.

Cheers,

--
Ignacio Machin,
ignacio.machin AT dot.state.fl.us
Florida Department Of Transportation

"Ryan Ternier" <rt******@icompasstech.com> wrote in message
news:uE**************@TK2MSFTNGP11.phx.gbl...
I'm having an issue with an inner loop.

Here's the basic Code:

For each......{

//Do code here

//start other loop
For each....{
...}
}

Everything works 100% when I step through the project, however when I break during the inner loop, and either:
1)Encounter an error
-or-
2)Stop the debugger

It will continue with all iterations of the 1st loop... and not touch the
2nd loop anymore. meaning running through 1000+ rows in a datatable and add them to an online DB.

Has anyone dealt with an issue like this? I'm working on sensitive
information and this issue is causing big problems.

Thanks!

/RT


Nov 16 '05 #4
Here's the First Loop:
foreach(DataRow row in tblItem.Rows)
{
//Get the FormID
int intFormID = 0;

//Get the FormID, then increment it by 1
strSQL = "SELECT MAX(FormID) from tblItems";
comItem.CommandText = strSQL;
intFormID = ToSQLValidInt(comItem.ExecuteScalar().ToString());
intFormID++;

//Add the item.
strSQL = strStart + "Values(" + row["SourceID"] + "," +
row["OwnerID"] + ",'" + row["ItemDate"] + "','" + row["DueDate"];
strSQL += "'," + row["StatusID"] + ",'" + row["StatusDate"] + "'," +
row["FollowUpID"] + "," + row["ModifiedBy"];
strSQL += ",'" + row["DateModified"] + "'," + row["GoalID"] + "," +
row["SubjectID"] + "," + row["GeographicAreaID"];
strSQL += "," + ToSQLValidBit(row["IsActive"]) + ",'" +
row["Description"] + "'," + row["CreatedBy"] + ",'" +
row["DateCreated"];
strSQL += "'," + intFormID + ")";
comItem.CommandText = strSQL;
comItem.ExecuteNonQuery();

//get the ID of the new item added to the DB.
strSQL = "SELECT IDENT_CURRENT('tblITems')";
comItem.CommandText = strSQL;
intItemID = Int32.Parse(comItem.ExecuteScalar().ToString());
intOldItemID = Int32.Parse(row["ItemID"].ToString());
//Update the Current Item, to change the Type of it, depending on
what is filled in with the V1 table.
strSQL = "UPDATE tblItems SET TypeID = ";
//Find out what Type the item is. Resolution or Complaint
if(row["Resolution"].ToString() != "")
{
strSQL += "1 WHERE ItemID = " + intItemID;
comItem.CommandText = strSQL;
comItem.ExecuteNonQuery();
ResolutionItemRecords(comItem,row,intItemID);
}
else if (row["ConcernDescription"].ToString() != "")
{
strSQL += "3 WHERE ItemID = " + intItemID;
comItem.CommandText = strSQL;
comItem.ExecuteNonQuery();
ComplaintItemRecords(comItem,row,intItemID);
}

/*What tables need to be done for Each Item:
* tblTasks, tblAmendments, tblAgainst, tblItemCategories,
tblItemAttachments */
ItemAmendmentConversion(tblItem, intItemID, intOldItemID);
ItemAttachmentConversion(tblItem, intItemID, intOldItemID);

TaskConversion(tblItem,intItemID, intOldItemID);

}//foreach
}

------------
And here's the 2nd loop (TaskConversion) don't worry about the Amendment
/ Attachment Conversions
------------

private void TaskConversion(DataTable tblItem, int intItemID, int
intOldItemID)
{
/*Purpose: When an item is created, all tasks that are associated
with that item must
* be coppied over, keeping the itemID the same as that
previously added.
*
* Tables That are related to tblTasks: tblItems, tblStaff,
tblFollowUps(v2)
*/
//Create the Tasks Table.
DataTable tblTasks = new DataTable("tblTasks");
tblTasks = CreateTable("tblTasks", strDBV1, tblTasks);
SqlConnection conItem = new
SqlConnection(System.Configuration.ConfigurationSe ttings.AppSettings["Up
dateConnection"]);
conItem.ConnectionString += strDBV2;
int intTaskID = 0;
SqlCommand comItem = new SqlCommand();

comItem.Connection = conItem;
comItem.Connection.Open();

//After the items have been transfered over, it's time for the tasks.
string strSQL = "";
string strStart = "";

//ItemID, and IsActive must be created using functions.
strStart = "INSERT INTO tblTasks(ItemID, OrderID, OwnerID, TaskDate,
Description, PriorityID, DueDate, StatusID, StatusDate, " +
"ModifiedBy, DateMOdified, CreatedBy, DateCreated, isActive)";

/*Loop through each row within the Tasks Table.
* If the ItemID in the row = the intItemID passed into this function
* then go ahead and add this data to the DB
*/
try
{
foreach(DataRow row in tblTasks.Rows)
{
//Loop through each row, but we can only add tasks that are part of
the current item.
//intOldItemID - the ItemID will be replaced with the new ItemID.
if(Int32.Parse(row["ItemID"].ToString()) == intOldItemID)
{
int intOrderID = 0;

//Insert the NewData into the tasks table.
strSQL = strStart + "Values(" + intItemID + "," + row["OrderID"]
+ "," + row["StaffResponsible"] + ",'" + row["TaskDate"] + "','" +
row["Description"];
strSQL += "'," + row["PriorityID"] + ",'" + row["DueDate"] + "',"
+ row["StatusID"] + ",'" + row["StatusDate"];
strSQL += "'," + row["ModifiedBy"] + ",'" + row["DateMOdified"] +
"'," + row["CreatedBy"] + ",'" + row["DateCreated"] + "',1)";
comItem.CommandText = strSQL;
comItem.ExecuteNonQuery();

//Get the current task ID.
strSQL = "SELECT IDENT_CURRENT('tblTasks')";
comItem.CommandText = strSQL;
intTaskID = Int32.Parse(comItem.ExecuteScalar().ToString());

//For each Task these are the tables that need to be edited:
// tblDependecies, tblDependencies, tblTaskAttachments
}
}
}
catch(Exception ex)
{
Debug.WriteLine(ex.ToString());
}
finally
{
conItem.Close();
conItem = null;
comItem = null;
}

}

*** Sent via Developersdex http://www.developersdex.com ***
Don't just participate in USENET...get rewarded for it!
Nov 16 '05 #5

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

Similar topics

5
by: Trevor Perrin | last post by:
After running a simple loop around 100-200 million times, there's a speed drop of about a factor of 7. This happens within several minutes (on a 1.7 Ghz machine), so it's not that hard to see. ...
2
by: Ivo | last post by:
Hi, I have an audio file (.mid or .wav or .mp3) in an object element: <object id="snd" classid="CLSID:22D6F312-B0F6-11D0-94AB-0080C74C7E95"...
45
by: Trevor Best | last post by:
I did a test once using a looping variable, first dimmed as Integer, then as Long. I found the Integer was quicker at looping. I knew this to be true back in the 16 bit days where the CPU's (80286)...
5
by: masood.iqbal | last post by:
My simplistic mind tells me that having local variables within looping constructs is a bad idea. The reason is that these variables are created during the beginning of an iteration and deleted at...
2
by: Jim in Arizona | last post by:
Usually, If i need special formatting, I don't use the datagrid control and use a loop that processes a table for each record read from the database (as in classic asp) like so: ...
2
by: David | last post by:
Hi, I need some help sending records to a variable from a button click on my form. I have 3 tables involved. I need to pull out the first HEADER, then pull out that headers DETAILS, then...
5
by: Jeff | last post by:
Hey gang. I have a script that gets stats from a mssql db, and then inserts those stats into a temp table. where i can work with them as i wish. the problem is it isn't looping through all the...
6
by: Luke - eat.lemons | last post by:
Hi, Im pretty new to asp so all light on this question would be great. Basically i need to test to see what value is set (where to retrieve the data from) so ive done it like this: If...
10
by: Charlie Brown | last post by:
I am using something like the following function to loop through a recipe program I am working on. As I was writing it, I starting thinking this isn't going to work at all... but not I'm not so...
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: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
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...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
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
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,...
0
jinu1996
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...

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.