iOS Question ResultSet1.NextRow problem

Discussion in 'iOS Questions' started by Gigi59, May 13, 2015.

  1. Gigi59

    Gigi59 Member Licensed 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
     
  2. Erel

    Erel Administrator Staff Member Licensed User

    The code is:
    Code:
    Dim rs As ResultSet = SQL.Exec...
    Do While rs.NextRow

    Loop
    rs.Close
    The first call moves it to the first record.
     
  3. omidaghakhani1368

    omidaghakhani1368 Well-Known Member Licensed User

    after query,use rs.NextRow and then get fields
    for get all record you can use do while
     
  4. Gigi59

    Gigi59 Member Licensed 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?
     
  5. Erel

    Erel Administrator Staff Member Licensed User

    No.

    This code should print all results:
    Code:
    Dim rs As ResultSet = SQL.Exec
    Do While rs.NextRow
     
    Log(rs.GetString("ID"))
    Next
     
  6. dieterp

    dieterp Active Member Licensed 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?

    Code:
    '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
     
  7. tufanv

    tufanv Expert Licensed User

    I couldn't understand how
    Code:
    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.
     
  8. klaus

    klaus Expert Licensed 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' !
     
  9. dieterp

    dieterp Active Member Licensed 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.

    Code:
    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.

    Code:
    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?
     
  10. dieterp

    dieterp Active Member Licensed User

    Klaus, is there a more elegant way of performing the operation for what I'm trying to achieve?
     
  11. klaus

    klaus Expert Licensed User

    I think that your solution is OK.
     
  12. dieterp

    dieterp Active Member Licensed User

    Thanks Klaus!
     
Loading...
  1. This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
    By continuing to use this site, you are consenting to our use of cookies.
    Dismiss Notice