B4J Question jRDC2 get specific column within row?

techknight

Well-Known Member
Licensed User
Longtime User
I am working with jRDC2 for the first time, but its not clear to me how to get a specific column within a row...

For example, this works, but it prints everything:
B4X:
        For Each row() As Object In res.Rows
            For Each record As Object In row
                Log(record)
            Next
        Next

However, when I try to do this, it doesnt work?
B4X:
        For I = 0 To res.Rows.Size-1
            Log(res.Rows.Get(I))
        Next

So I assume my method is incorrect, and because I dont know what "row" is in the For Each statement, I cant seem to figure it out either.

Thoughts?

In some cases I don't want the entire row of data, just a specific column say at column 3.
 

Chris2

Active Member
Licensed User
Longtime User
To expand my answer a bit, I *think* that...

a) Each row() in res.Rows holds a single returned result from your query. The size of row() is the number of columns/values your query returns for each result.
b) res.Columns.Get("NameOfColumn") returns the index of the named column in the array row().
Hence
B4X:
For Each row() As Object In res.Rows
       Log(row(res.Columns.Get("NameOfColumn")))
Next
will print the value in the named column for each row returned by the query.

If you know the index of the column you're after from your query, then you could just use
B4X:
Log(row(ColumnIndex))
but to me, using the column name is much more readable when you look back at the code,
 
Upvote 0
Top