ASP Rs. getrows Method

Source: Internet
Author: User

You may often encounter this situation:

sql="select * from table"set rs=conn.execute(sql) 

After the preceding two statements are executed, if response. Write Rs. recordcount is used, result-1 is returned. However, there are actually records in the record set Rs. To get the correct total number of records, we use getrows.

SQL = "select * from table" set rs1_conn.exe cute (SQL) ARRA = Rs. getrows 'place the record set in a two-dimensional array response. Write ubound (ARRA, 2) + 1

The total number of records in the record set is obtained.

response.write ubound(arrA,1)+1 

========================================================== ============================

In addition, there is also a way to get the total number of records:

jls= conn.execute("Select count(*) From table").getstring 

At this time, the value of the variable JLS is the total number of records.
The getrows method returns a two-dimensional array variable. Each row corresponds to a record in the recordset, and each column corresponds to the column in the record. The syntax of this method is as follows:

varArray = rs.GetRows([Rows], [Start], [Fields])  

Rows indicates the number of records to be read. If you want to obtain all records of the recordset, use-1 or omit this parameter. Start indicates the first bookmark to be read. It can also be one of the following enumerated constants: 0-adbookmarkcurrent (current record), 1-adbookmarkfirst (first record), or 2-adbookmarklast (last record ).

Fields is an array of field names that can be selected to limit the amount of data to be read. (You can also specify a single column name, a single column index, or a column Index Array ). When rows is set to less than the number of records in the recordset, the First unread record becomes the current record. If the rows parameter is omitted or set to-1-adgetrowsrest or greater than the number of unread records, the getrows method reads all records and puts the recordset In the EOF state without generating any errors.

When processing the data of the target variable array, remember that the data storage method is a bit opposite: the first dimension of the array defines the recordset field (Data row ), the second dimension defines the recordset data column. The following is an example of loading A recordset with three columns for all records:

Dim values As Variant, fldIndex As Integer, recIndex As Integer     values = rs.GetRows(, , Array("LastName", "FirstName", "BirthDate"))     For recIndex = 0 To UBound(values, 2)      For fldIndex = 0 To UBound(values)      Print values(fldIndex, recIndex),      Next      Print     Next  

The getrows method is usually faster than the loop of a record to be read at a time, but when using this method, you must ensure that the recordset does not contain too many records; otherwise, it is easy to fill up all the memory with a very large array of variables. Based on the same reason, be careful not to include any blob (Binary Large Object) or clob (character large object) field. If you do so, the application will be cracked, especially for large recordset. Finally, remember that the array of variables returned by this method is based on 0. The number of records returned is ubound (values, 2) + 1, and the number of records returned is ubound (value, 1) + 1.

 

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.