what is going wrong within this loop please?

PiggyZhou

Member
Joined
Aug 22, 2008
Messages
5
Programming Experience
Beginner
Hi, all experts here,
Thank you for your kind attention.
I have encountered a very strange problem with my code doing the loop which I just dont know what is going wrong with it.
Please see the code below:

While (myReader.Read())
if (condition) then

i = i + 1
MsgBox(i)
MsgBox("The" & "" & i & " package is" & "" & myReader.GetString(0))
Opkg.LoadFromSQLServer("servername", "username", "password", DTS.DTSSQLServerStorageFlags.DTSSQLStgFlag_Default, "", "", "", myReader.GetString(0))
Opkg.SaveToSQLServer("newservername", "username", "password", DTS.DTSSQLServerStorageFlags.DTSSQLStgFlag_Default, "", "", "", myReader.GetString(0))


end if

The strange thing about it is : The loop work fine and displays me the results I wanted but if I add the two code lines as seen highlighted in red then it did not loop to the end which ended after the first iteration?
Can anyone give me any ideas what is going wrong with that? Why the two code lines there caused that problem?
I am looking forward to hearing from you and thanks a lot for your kind help .
Best regards,
Yours sincerely,
 
Try something like this:
VB.NET:
Dim TempString As String
While (myReader.Read())
if (condition) then

i += 1
TempString = myReader.GetString(0)
MsgBox("The " & i & " package is " & TempString )
Opkg.LoadFromSQLServer("servername", "username", "password", DTS.DTSSQLServerStorageFlags.DTSSQLStgFlag_Default , "", "", "", TempString)
Opkg.SaveToSQLServer("newservername", "username", "password", DTS.DTSSQLServerStorageFlags.DTSSQLStgFlag_Default , "", "", "", TempString)

end if
 
Hi,
Thanks for your kind advice.
It still remains the same problem though.
I am really stuck in this problem not knowing what is going wrong with it.
Any more ideas, suggestions?
Thanks a lot.
Best regards,
Yours sincerely,
 
Hi,
Thanks for your kind help and advices.
By checking and I just realized that it is not something to do with the loop code, the problem is the files I am trying to load from the SQL Server instance within the loop. The thing is within the loop, the memory basically places everything into a so-called collection and because it does not allow the duplicate item within the collection, therefore it results in the failure within the loop. I now have to find a way for clearing up the memory after each iteration within the loop to make things work.
Hope all experts here could give me any kind help and advices on this issue.
I am looking forward to hearing from you and thanks a lot in advance.
Best regards,
Yours sincerely,
 
I'm assuming that by 'clearing uo the memory' you mean to say that you need to re-initialize the Opkg object, right?

Assuming I'm right (I know, one should never assume anything) you could set Opkg to a new instance at the beginning of each loop
 
Back
Top