2010-09-14 72 views
0

我正在更新一些VB6代碼到.NET並遇到了一個小問題。我基本上是在一個無限循環,因爲我不知道NET的等效RecordSet.MoveNext()(VB6)。我更新了使用Recordset與數據集ASP/VB6到.NET轉換幫助

While Not _sqlADP.Fill(_dataSet) = 0 
    // code 
    // more code 

    // original VB6 code had _recordSET.MoveNext() here. 
End While 

如何檢查EOF在這裏並退出循環?

回答

4

我相信你會使用類似以下內容:

_sqlADP.Fill(_dataSet) 
For Each row As DataRow In _dataSet.Tables(0).Rows 

Next 

您可能還需要考慮使用DataReader,它可能更類似於VB6 RecordSet,因爲我相信ADO RecordSet具有隻讀,僅默認向前行爲。如果你正在使用DataReader,你的循環看起來像:

While _dataReader.Read() 

End While 
+0

Scott對於.NET來說非常方便。 – Maximillian 2010-09-14 20:09:11

2

這是C#,但你可以得到的想法......

foreach(DataRow row in _sqlADP.Fill(_dataSet).Tables[0].Rows) 
{ 
    // code here 
} 
0

我想出了一些我自己。這是一個非常簡單的解決方案,我很好。

Dim rowCount = _sqlADP.Fill(_dataSet) 
While Not rowCount = 0 
    // code 
    // more code 

    // original VB6 code had _recordSET.MoveNext() here. 

    rowCount = rowCount - 1 
End While 

編輯:沒關係,我去與斯科特·米切爾的解決方案。

+0

[Yuck](http://www2.tech.purdue.edu/cpt/courses/cpt355/C_Sharp_Coding_Standards_and_Guidelines.asp) – 2010-09-14 20:16:58