Click here to Skip to main content
15,887,027 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi Friends , today I came accross a very weired kind of situation.I am a beginer in vb.net so any help is greatly apprciated

VB
While Not linkfound

                   Try
                       t1 = DFSStk.Pop()
                   Catch ex As Exception
                       MsgBox("Stack is empty")
                       Exit While
                   End Try



                   While redr.Read()
                       root = redr.GetString(0)
                       nextNode = redr.GetString(1)

                       If root = t1 And nextNode = t2 Then
                           MsgBox("Direct LinkFound")
                           linkfound = True
                           Exit While
                       ElseIf root = t1 Then
                           DFSStk.Push(nextNode)
                       End If
                   End While


               End While


Now actually for the each iteration of Outer loop i need to search the complete tble linked with datareader. (datareader variable is redr Obj in my code).
But by the time complete iteration of iiner while loop complete for the first item of first while loop, the reder cursor is already at the end of the table.So it fails for the second iteration of outer while loop
Is there any way i can reset this to start of the datareader object, I dont want to load the table at each iteration.
thanks in advance
Posted
Updated 27-Jun-13 1:24am
v2

1 solution

I would suggest re-instantiating your redr object for each iteration of the outer loop as I do not believe there is a way to more an OLEDBReader back to the start.

As an alternative you could populate a datatable with the information then just read through that.

so outside your outer loop do something like:

VB
Dim dt as DataTable = new DataTable()
dt.Load(redr)

Then instead of your inner while do:

VB
ForEach dim dr as DataRow in dt.rows

root = dr(0).ToString()
nextNode = dr(1).ToString()

If root = t1 And nextNode = t2 Then
      MsgBox("Direct LinkFound")
      linkfound = True
      Exit For
ElseIf root = t1 Then
      DFSStk.Push(nextNode)
End If

next
 
Share this answer
 
v2
Comments
Shruti Sagar Mishra 27-Jun-13 9:09am    
Thanks Pheonyx...
It really helped alot
Pheonyx 27-Jun-13 9:11am    
No Problem, happy it helped.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900