views:

48

answers:

3

i'm updating some VB6 code to .NET and have come across a small problem. i'm basically in an infinite loop because i don't know the .NET equivalent of RecordSet.MoveNext() (VB6). i've updated the use of a RecordSet with a DataSet

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

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

how do i check for EOF here and exit the loop?

+2  A: 

This is C#, but you can get the idea...

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

I believe you'd use something like the following:

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

Next

You might also want to consider using a DataReader, which is probably more analogous to the VB6 RecordSet, as I believe the ADO RecordSet has read-only, forward-only behavior by default. If you were using a DataReader your loop would look like:

While _dataReader.Read()

End While
Scott Mitchell
Scott is pretty dang handy with .NET.
MadMAxJr
A: 

i figured something out myself. it's a very simple solution that i'm okay with.

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

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

    rowCount = rowCount - 1
End While

Edit: nevermind, i went with Scott Mitchell's solution.

[Yuck](http://www2.tech.purdue.edu/cpt/courses/cpt355/C_Sharp_Coding_Standards_and_Guidelines.asp)
Chris Shouts