techknight Well-Known Member Licensed User Longtime User Apr 28, 2022 #1 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: Code: 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? Code: 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.
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: Code: 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? Code: 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.
C Chris2 Well-Known Member Licensed User Longtime User Apr 28, 2022 #2 B4X: For Each row() As Object In res.Rows Log(row(res.Columns.Get("NameOfColumn"))) Next Upvote 1
C Chris2 Well-Known Member Licensed User Longtime User Apr 29, 2022 #3 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
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,
techknight Well-Known Member Licensed User Longtime User May 3, 2022 #4 I will have to give it a try and see what happens Upvote 0