Rs. GetRows use detailed

Source: Internet
Author: User
Tags format array integer return variable
Detailed

ADO also provides a more efficient way to get information. The GetRows method returns a two-dimensional array variable, each row is recorded in a recordset, and each column is applied to the log in the record. The language of 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 of the recordset's records, you can use-1 or omit the parameters. Start is the first book to be read; it can also be one of the following columns: 0-adbookmarkcurrent (current record), 1-adbookmarkfirst (first record), or 2-adbookmarklast (last recorded).

The Fields is an optional name array used to limit the amount of data to be read. (You can also specify a single column name, a single row index, or a row index array). When you set rows to less than the recordset, the first unread record becomes a record. If you omit Rows parameters or are -1-adgetrowsrest or larger than the number of unread strokes, the GetRows method will read all the records and let the Recordset in the EOF state without producing any bugs.

When dealing with a variable array of data, it should be remembered that the data storage method is somewhat opposite: the column of the first definition recordset in the array (the data row), and the second defines the data columns of the recordset. Here's a sample of all the three places in the recordset that you can download:

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 a single recorded loop, however, when using this method, it is necessary to make sure that the recordset does not contain too many records; otherwise, it is easy to fill all the memories with a very large variable array. For the same reason, be careful not to include any blob (Binary Large object) or Clob (Character Large object), and if so, the application will explode, particularly for larger recordsets. In the end, remember that the return of this method is based on a 0 base, and the number of the Returned records is UBound (values,2) +1, and the return of the column is UBound (value, 1) +1.

The GetString method is similar to GetRows, but it is passed back to multiple records in a single string form. The GetString language is as follows:

GetString ([Format], [NumRows], [Coldelimiter], [RowDelimiter], [nullexpr])

Format is the form of the results. GetString may also be able to support more formats, but the only format currently supported is 2-adclipstring, so there's actually no choice. NumRows is the number of columns to be obtained. (Use-1 or omit this argument to read all the remaining records.) Coldelimiter is a delimited character of the row (a tab character). RowDelimiter is a record separator character (preset as a newline character). A nullexpr is a string that is used to represent a null field (preset as an empty string). It is stated in the file that the last three parameters are only available when format= adclipstring, but this warning is not very meaningful because (as previously mentioned) this format is currently the only support. Here's an example, which passes through the GetString method of converting data to a separate text file:

Dim I as Long
Open "Datafile.txt" for Output as #1
For i = 0 to Rs. Fields.Count _ 1 ' Export field names.
If i > 0 Then Print #1, ";";
Print #1, Rs. Fields (i). Name;
Next
Print #1, ""
Rs. MoveFirst ' Export data.
Print #1, Rs.  GetString (,, ";", vbCrLf); ' Don ' t add an extra CR-LF here.
Close #1

The GetString method does not allow you to simply remit a subset of the bars, or modify the order of the outbound bars. If you need these extra features, you should use the GetRows method and build your own results strings.



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.