iOS Question ResultSet1.NextRow problem

Gigi59

Member
Licensed User
Longtime User
hi all,
someone can tell me how do I see the first record with nextRow? always begins with the second
sorry for the question but I'm a beginner
Thanks
Regards
 

Gigi59

Member
Licensed User
Longtime User
Hi Erel
I'm sorry, but I can see the first record only in this way


Dim rs As ResultSet = SQL.Exec...
If rs.NextRow=true then
dim id as int = rs.GetString("ID") ' FIRST RECORD
End If

DoWhile rs.NextRow
dim id as int = rs.GetString("ID") ' FROM SECOND RECORD TO END

Loop
rs.Close

is it correct?
 
Upvote 0

dieterp

Active Member
Licensed User
Longtime User
I seem to have a similar issue as Gigi59 above. Erel's answer does work, but how do we do it if we want to first check that records exist, perform some code if they do (And other code if they don't) and then iterate through all the records? Below is some code/comments on what I've done to achieve my objective. Is this the correct way?

B4X:
'Assume we've set the SQL ResultSet to CursorVenueDescription

If CursorVenueDescription.NextRow = True Then 'Check if there are records

        NoVenues = False 'Run some code
        btnSave.Enabled = True
      
        lstVenues.AddSingleLine(CursorVenueDescription.GetString("Description")) 'I have to put this in here if I want to add the 1st record to the list
      
        Do While CursorVenueDescription.NextRow
            lstVenues.AddSingleLine(CursorVenueDescription.GetString("Description")) 'This will add records 2 to end to the list
        Loop

        CursorVenueDescription.Close

    Else

        NoVenues = True    'Run other code if no records exist
        lstVenues.Visible = False

    End If
 
Upvote 0

tufanv

Expert
Licensed User
Longtime User
I couldn't understand how
B4X:
Do While CursorVenueDescription.NextRow
            lstVenues.AddSingleLine(CursorVenueDescription.GetString("Description")) 'This will add records 2 to end to the list
        Loop
can't add the first entry but adds the entry number 2 to end . Are you sure ? I always use this method and it adds every single line.
 
Upvote 0

dieterp

Active Member
Licensed User
Longtime User
As I'm seeing it, it will add each entry from 1 to n if you use the block of code below and only that code after you have set the ResultSet.

B4X:
Do While CursorVenueDescription.NextRow
            lstVenues.AddSingleLine(CursorVenueDescription.GetString("Description")) 'This will add records 2 to end to the list
Loop

If however you use the code below after setting the ResultSet to check if records exist, it moves to the first record of the ResultSet when you perform any code in the 'If' statement.

B4X:
If CursorVenueDescription.NextRow = True Then

After that when you use 'DoWhile CursorVenueDescription.NextRow' in the 'If' statement, it will start with the next record which is the 2nd record in the ResultSet.

I'm just not sure which is the most elegant way to traverse through a ResultSet where you actually want to perform tasks while doing that?
 
Upvote 0

dieterp

Active Member
Licensed User
Longtime User
@dieterp
If you use the code in post #6 it's normal that you need to add the the lstVenues.AddSingleLine(... line.
Because If CursorVenueDescription.NextRow = True Then consumes the first 'NextRow' !
Klaus, is there a more elegant way of performing the operation for what I'm trying to achieve?
 
Upvote 0
Top