使用OLEDBReader在VB.Net中进行双循环 [英] Double Looping in VB.Net using OLEDBReader

查看:118
本文介绍了使用OLEDBReader在VB.Net中进行双循环的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

嗨朋友们,今天我来到了一个非常疲惫的局面。我是vb.net的初学者,所以任何帮助都会得到极大的帮助



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

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





现在实际上对于Outer循环的每次迭代,我需要搜索与datareader链接的完整tble。 (datareader变量在我的代码中是 redr Obj)。

但是当第一次while循环的第一项完成iiner while循环完成时,reder光标是已经在表的末尾。所以它在外部while循环的第二次迭代失败

有没有办法我可以重置这个以启动datareader对象,我不想加载表在每次迭代。

提前感谢



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

推荐答案

我建​​议为每次迭代重新实例化 redr 对象因为我不相信有一种方法可以让OLEDBReader重新开始。



作为替代方案,您可以使用这些信息填充数据表请仔细阅读。



所以在你的外圈之外做类似的事情:



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:

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



然后代替你的内心做:




Then instead of your inner while do:

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


这篇关于使用OLEDBReader在VB.Net中进行双循环的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆