You can use a ResultSet
object to execute a query and browse the query results.
When you create queries using the QueryDef
Object, you must create a corresponding ResultSet object to run
the query and obtain the results. Each ResultSet object is customized for
the query it is running. The ResultSet object contains data structures that
organize data from the query into rows and columns, where each row represents
a single data record and each column represents one field from that data record.
After running the query, you can navigate (move) from row to row, and from
column to column, to obtain the data you want.
Notez ce qui suit :
- Columns are numbered from (1 through N), not (0 through
N-1).
- After the result set is generated, you may need to fill
in parameter values, if it is a parameterized query.
- After the result set is generated and parameters (if any)
are set, you may execute it to see the output of the query. It is permitted
to execute the result set multiple times, if you wish to rerun the query.
(Perhaps you have cleared and reset the parameter values.) It is also legal
to get the SQL for the query.
- Conceptually a query may generate so much output that it
would be impossible or greatly inefficient to just copy it from the database
over into the memory of the program. So, you have to use a "cursor" to navigate
through the output, using the MoveNext method.
- Immediately after executing the result set, the cursor
is positioned "just before" the first item, so you have to call MoveNext before
you can extract the first value.
- To get the value after you are positioned, use the GetColumnValue method.