NextRecordset and GetRows Duet Ensemble ~ ~

Source: Internet
Author: User
Tags array query
NextRecordset and GetRows people may use very little!
Recently used, good dongdong!
To improve the batch query, the query record set is not huge huge situation is very effective
NextRecordset and GetRows are two attributes of the Recordset (property or method I'm a regular confuse #$#$, I can't make it clear.)

GetRows---> Extracts recordset recordset into a two-dimensional array, our behavior of the recordset data is transferred to the array, we can disconnect the record set early, no longer use metadata operations, rs.movnext, while not Rs.eof and so on can be skipped

NextRecordset----> is to provide a way to move from the current working recordset to the second recordset in the case of submitting multiple queries at once, forming multiple reordset result sets!
is mainly used in the case of a result set formed by multiple select

Examples are as follows:

Dim sql,rs,arra,arrb,rowsa,rowsb

' = = = = Extract Database Library record = =

(Adodb.connection the connection part is omitted, assuming Conn.Open connstr)
Sql= "Select Ca1,ca2,ca3,ca4 from TableA" '---------------SELECTa
sql=sql& "Select cb1,cb2,cb3,cb4,cb5 from TableB" '-------------SELECTB

Set Rs=conn.execute (SQL)
' The result of the execution will have two select result sets, and the recordset for the first select is currently active

Arra=rs. GetRows '----------obtain a two-dimensional array of Selecta recordset

Set Rs=rs. NextRecordset
'------------the most critical step, activate the next recordset using NextRecordset

Arrb=rs. GetRows '----------to get another two-dimensional array of the second SELECTB recordset

Rs.close
Set rs=nothing '---------release database objects as soon as possible, turn off the recordset
Conn.close
Set conn=nothing
In this way, all of our data on the database clean extraction complete, with the earliest time to release the database resources
'-----------//

' ======== with Arra ARRB for page processing, showing data results = =
' Note that the arra=getrows gets the array, the first dimension represents the column, and the second dimension represents the row

Rowsa=ubound (arra,2) '----extracts the ARRA's second-dimensional subscript, which is equivalent to the number of record rows obtained from the recordset
Rowsb=ubound (arrb,2) '-----Ibid., extract the second dimension subscript of ARRB

' Do the data loop:

' The loop of the first select table
Response.Write "<table>"
For I=0 to ROWSA
Response.Write "<tr>
Response.Write "<td>" &arra (i,0) & "</td>" ' TABLEA.CA1
Response.Write "<td>" &arra (i,1) & "</td>" ' TABLEA.CA2
Response.Write "<td>" &arra (i,2) & "</td>" ' TABLEA.CA3
Response.Write "<td>" &arra (i,3) & "</td>" ' tablea.ca4
Response.Write "</tr>"
Next
Response.Write "</table>

' Second Select Table loop
Response.Write "<table>"
For I=0 to ROWSB
Response.Write "<tr>
Response.Write "<td>" &AMP;ARRB (i,0) & "</td>" ' TABLEB.CB1
Response.Write "<td>" &AMP;ARRB (i,1) & "</td>" ' TABLEB.CB2
Response.Write "<td>" &AMP;ARRB (i,2) & "</td>" ' tableb.cb3
Response.Write "<td>" &AMP;ARRB (i,3) & "</td>" ' TABLEB.CB4
Response.Write "<td>" &AMP;ARRB (i,4) & "</td>" ' tableb.cb5
Response.Write "</tr>"
Next
Response.Write "</table>

'--------over

REM ' ============ Summary ========

Such a result, again clear!
(1) The use of NextRecordset, you can handle multiple SELECT statements to send the resulting set of results, reduce network traffic, must speed up!
This is done without using NextRecordset:
Sql= "Select Ca1,ca2,ca3, Ca4 from TableA"
Set Rs=conn.execute (SQL)
Sql= "Select Cb1,cb2,cb3,cb4,cb5 from TableB"
Set Rs=conn.execute (SQL)
(2) using GetRows to extract the recordset into the array (memory, so the recordset is not required to be sea big)
Work with an array of memory, and dispense with the judgment of Eof,movenext, who is quicker! Don't say it!
(3) The most important, we use the two, a one-time to all the data, quickly disconnect the database and destroy the creation of recordset database objects, greatly reduce network traffic! Performance naturally to improve a lot!

'-----------hehe! Timely original, first light dark color, forgive me forgive ~~~~~~~v37




Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.