To see the rs.getrows more clearly _ Application skills

Source: Internet
Author: User
Rs.getrow Brothers know that Rs.getrow can be more efficient to obtain small capacity data (not suitable for large-capacity data, especially when large objects, easy to burst out, I blew it once), Puterjam applied Well said.

But Rs.getrow returns a two-dimensional array, and we often don't know which segment is right. This is very troublesome, so a small section of the program to facilitate debugging:


Dim DS
Set Objrs=objconn.execute ("select * from [Blog_upload] WHERE ([ul_quote] like '%" & CStr (ID) & "%")
Ds=objrs.getrows
Objrs.close ()
Set objrs=nothing

' Create a table
Response.Write "Written by Sipo (www.dc9.cn) <table align=" "Center" "Border=" "1" ">"
Response.Write vbCrLf
Response.Write "<tr><td></td>"
For j = 0 to UBound (DS, 1)
Response.Write "<td>ds" ("&j&", X) </td> "
Next
Response.Write "</tr>"
' Each row
For i = 0 to UBound (DS, 2)
Response.Write "<tr><td>ds (X," &i& ") </td>" & vbCrLf
' Each column
For j = 0 to UBound (DS, 1)
Response.Write "<td>"
If IsNull (DS (J, i)) Then
Response.Write "Null"
Else
Response.Write DS (J, i)
End If
Response.Write "<br>"
Response.Write "<b>ds" ("&j&", "&i&") </b> "
Response.Write "</td>"
Next

Response.Write "</tr>" & vbCrLf
Next

Response.End






--------------------------------------------------------------------------------

To our Rookie:
Small information on GetRows:


ADO also provides a more efficient way to get data. The GetRows method returns a two-dimensional array variable, each row corresponds to a record in the Recordset, and each column corresponds to a field in the record. The syntax for this method is as follows:

Vararray = Rs. GetRows ([Rows], [Start], [Fields])

Rows is the number of records to read, and if you want to get all the records for the recordset, use 1 or omit this parameter. Start is the bookmark that indicates the first read record, or one of the following enumeration constants: 0-adbookmarkcurrent (current record), 1-adbookmarkfirst (the first record), or 2-adbookmarklast (last record).

Fields is an array of field names that you can select to limit the amount of data to read. (You can also specify a single field name, a single field index, or an array of field indices.) When you set Rows to be less than the recordset record number, the first unread record becomes the current record. If you omit the Rows parameter or are set to -1-adgetrowsrest or greater than the number of unread pens, the GetRows method reads all the records and lets the recordset in EOF state without any errors.

When dealing with the data for an array of destination variables, you should remember that the data is stored in a somewhat opposite sense: the first dimension in the array defines the field (data row) of the Recordset, and the second dimension defines the data columns for the recordset.

The GetRows method is usually faster than a single record-reading loop, but when you use this method, you must make sure that the recordset does not contain too many records; otherwise, it's easy to fill up all the memory with a very large array of variables. For the same reason, be careful not to include any blob (Binary Large object) or Clob (Character Large object) field; If so, the application will certainly explode, especially for larger recordsets. Finally, remember that the array of variables returned by this method is 0-based; the number of strokes returned is UBound (values,2) +1, and the number of fields 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.