VBA macros: ADODB. Recordset's properties and methods __VBA macros

Source: Internet
Author: User

To more accurately track data, you create a cursor that contains data using the Recordset component, which is the data stored in memory:

rs = Server.CreateObject ("ADODB.") RecordSet ")

Rs. Open (Sqlstr,conn,1,a)

Note: a=1 means read data, a=3 represents new, modified, or deleted data.

In the recordset component, the common properties and methods are:

Rs. Fields.Count:RecordSet the number of object fields.

RS (i). Name: The names of the I fields, I are 0 to Rs. Fields.count-1

RS (i): Data in the I field, I is 0 to Rs. Fields.count-1

RS ("field name"): Specifies the data for the field.

Rs. Record.count: Total number of data records.

Rs. EOF: Is the last record.

Rs. MoveFirst: Point to the first record.

Rs. MoveLast: Point to last record.

Rs. MovePrev: Point to previous record.

Rs. MoveNext: Point to next record.

Rs. GetRows: Put the data in an array.

Rs. The number of Properties.Count:ADO resultset or connection properties.

Rs. Properties (item). The name of the ResultSet or connection of the Name:ado.

Rs. The value of the ResultSet or connection of the Properties:ado.

Rs.close (): Closes the connection.

Use ADO Connection database query, the database will query results returned to the query, in the query end of the memory inside there will be a list, this list is the result of the query. The list in memory is the dataset. In your program RS means this dataset. BOF means that the current pointer to Rs is in front of the dataset, for example, there are 4 records numbered 1,2,3,4 in the dataset, but Rs points to the number 1, which is consistent with the BOF. Similarly, when the RS pointer points to 5, and the fifth record does not exist, this results in EOF.

If both the BOF and the aof are generated, that is, the RS pointer is both outside the upper bound and next, so there is only one case where the data set represented by RS is empty, so that the RS pointer is both BOF and EOF, wherever it refers.

Your situation is estimated that the SQL statement query out of the value is empty, so the dataset is also empty, when reading the value in the RS dataset will be reported this error.
Using the If Rs.bof and rs.eof then this judgment can determine whether there is no data set in RS, if this condition, the data set is empty, in the program will bypass the RS field access

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.