It seems that the B4XTable is more of a visual (view?) than an object to hold database data. I have had some success with it having only just tried it today but I wonder if I am over complicating things.
Here is a generic sql subroutine to populate a table so I can access the data in my app:
And I am using it to populate a combobox like this:
I have spent ages trying to work out how to get the number of rows in the table to no avail, hence me cheating by using putting the size of the list that is the table source in the table tag.
Is this a good use of B4Xtables if I am not going to actually show the data table?
Of the many things that confuse me, one is why is B4xTable.Getrow(0) always null, row(1) is the first result form my query. And another is how can I get the number of populated rows? (B4XTable.size returns 0)
Am I misusing B4xTables?
Here is a generic sql subroutine to populate a table so I can access the data in my app:
generic sql query:
private Sub do_sql(sq As String) As B4XTable
Dim table As B4XTable
Dim lst As List
lst.Initialize
Dim RS As SD_ResultSet = MYSQL.ExecQuery(sq)
Dim colcount As Int = RS.ColumnCount
Dim colnames(colcount) As String
table.Initialize("","")
For i = 0 To colcount -1
colnames(i) = RS.GetColumnName(i)
table.AddColumn(colnames(i), table.COLUMN_TYPE_TEXT)
Next
Do While RS.NextRow
Dim row(colcount) As Object
For i = 0 To colcount -1
row(i) = RS.getstring(colnames(i))
Next
lst.Add(row)
Loop
RS.Close
table.SetData(lst)
table.Tag = lst.size
Return table
End Sub
And I am using it to populate a combobox like this:
B4X:
humantable = do_sql("Select * from Humans")
cmbHuman.cmbBox.Clear
For i = 1 To humantable.tag
cmbHuman.cmbBox.Add(humantable.Getrow(i).Get("Name"))
Next
Is this a good use of B4Xtables if I am not going to actually show the data table?
Of the many things that confuse me, one is why is B4xTable.Getrow(0) always null, row(1) is the first result form my query. And another is how can I get the number of populated rows? (B4XTable.size returns 0)
Am I misusing B4xTables?