B4J Question B4J SQL Read last and sixth data records

strupp01

Active Member
Licensed User
Longtime User
I want to read out the last and the 6th record of the 'Druck_Ein' column from an SQL table 'PLD'.

Dim RS As ResultSet = sql_PLD.ExecQuery("SELECT Druck_Ein FROM PLD")

How is it going on, or is the approach wrong?
 

EnriqueGonzalez

Well-Known Member
Licensed User
Longtime User
i suggest you that for those kind of queries, use:

you will get a list, use that list to travel thru all the resultset information.
B4X:
'Creates a list from a resultset
'stringargs(): if Query has Question Marks pass array of parameters, otherwise pass null
'Limit: total number of rows to take from DB, pass 0 to all
Public Sub ExecuteMemoryTable(Query As String, StringArgs() As String, Limit As Int) As List
    Dim cur As ResultSet
    If StringArgs = Null Then
        Dim StringArgs(0) As String
    End If
    cur = SQL1.ExecQuery2(Query, StringArgs)
    Dim table As List
    table.Initialize
    Do While cur.NextRow
        Dim values(cur.ColumnCount) As String
        For col = 0 To cur.ColumnCount - 1
            values(col) = cur.GetString2(col)
        Next
        table.Add(values)
        If Limit > 0 And table.Size >= Limit Then Exit
    Loop
    cur.Close
    Return table
End Sub
 
Upvote 0

strupp01

Active Member
Licensed User
Longtime User
I had hoped that there is a command as under B4A, which provides the result directly. For tables with 20,000 lines, it takes a while. I'll try it. Thank you.
 
Upvote 0
Top