Android Question Sorting a List that comes from SQL DDB

Arf

Active Member
Licensed User
I've been looking at this:
Persons.SortType("Age", True) 'Sort the list based on the Age field.

to sort a list of patients, but my list of patients is populated from the database, like this:
B4X:
Patients.patlist = DBUtils.ExecuteMemoryTable(SQL,"SELECT * FROM Patients",Null,0)
and the n gets put into another list to display in a table, like this:
B4X:
For i=0 To patlist.Size - 1
        Dim pp(5) As String
        pp = patlist.Get(i)
        List1.Add(Array As String(pp(0), pp(1),pp(2),DateTime.Date(pp(3)),pp(4)))
       
    Next
I want to sort the list based on the contents of the last column, but I don't know how to do this given that there isn't a Type for my data. How can I do this?
 

jsanchezc

Member
Licensed User
Use ORDER BY ...
Patients.patlist = DBUtils.ExecuteMemoryTable(SQL,"SELECT * FROM Patients ORDER BY NAME",Null,0)
If need invert order:
Patients.patlist = DBUtils.ExecuteMemoryTable(SQL,"SELECT * FROM Patients ORDER BY NAME DESC",Null,0)
Can combine more fields
Patients.patlist = DBUtils.ExecuteMemoryTable(SQL,"SELECT * FROM Patients ORDER BY NAME, PHONE ",Null,0)
And combine inverted
Patients.patlist = DBUtils.ExecuteMemoryTable(SQL,"SELECT * FROM Patients ORDER BY NAME DESC, PHONE ",Null,0)
 
Top