StrataFrame Forum

The Do - Loop While BO.MoveNext does not cycle through all of the records

http://forum.strataframe.net/Topic18141.aspx

By Jeff Pagley - 7/28/2008

 Hi SF Team,

Below is an example of some logic I am using in my app and found it was not cycling through all of the records.    Unless I execute the BO.MoveFirst() method before the do loop,  it does not cycle through all of the records .   Why do I have to execute the .MoveFirst method to use this logic?   Would it be better to use .GetEnumerable method of the BO instead?

Thanks Guys,

Jeff

 

Using lo As New DepartmentsBO

lo.FillDataTable("SELECT * FROM CMPRDepartments")

lo.MoveFirst()

Do

Debug.Print(count & " - Department = " & lo.DepartmentDescription)

Loop While lo.MoveNext

End Using

By Trent L. Taylor - 7/28/2008

That is correct, but you should really be using the GetEnumerable if you don't want to worry about the MoveFirst:

For Each bo As MyBO in MyBOInstance.GetEnumerable()
   '---
Next
By Greg McGuffey - 7/28/2008

I'm not sure about why you have use MoveFirst(), but I've run into this before, on a freshly filled BO. In any case, GetEnumerable() is the better choice. It will cycle through all the rows and it makes sure the current index is restored when done.
By Peter Jones - 7/29/2008

Hi Jeff,

We just use GetEnumerable once we found out about it and refactored all old code. Prior to that we did (without any problems):

    If BO.MoveFirst() Then
        Do


        Loop While BO.MoveNext()
    End If

This code is better as I believe your example will error if the BO is empty on the MoveFirst.

Cheers, Peter

By Jeff Pagley - 7/29/2008

Hi Peter,

You are absolutely right.  I am now to using GetEnumerable and I am refactoring all of the old code.

Thanks, Jeff