what does rs.Fields(0) mean? (ADODB) VBA
dim rs As ADODB.Recordset
...
...
...
capture_id = rs.Fields(0)
wha开发者_C百科t does .Fields(0) mean?
the first column from the recordset (0) is the first (1) is the second etc etc
example, if this is your query
select LastName, FirstName
from YourTable
In this case s.Fields(0) would return column LastName and rs.Fields(1) would return column FirstName
It's pulling the first column from the current row in the result set.
Fields(x)
lets you access fields by a numerical index starting at 0.
Edit:
Example:
If the result set has two columns: foo
and bar
..
rs.Fields(0)
would return the value of column foo
,
and
rs.Fields(1)
would return the value of column bar
.
I would NEVER, EVER use this syntax. This is dependant on the query always having the same field in the first position.
Furthermore this would only save a minute amount of time. (As in milliseconds if not less.)
Please, for the love of God, per proper programming practice, change that to use the field name. This almost, but not quite, belongs on the www.dailywtf.com website.
精彩评论