Three days to learn the third day of ADO

Source: Internet
Author: User
Tags filter definition comparison copy insert table name valid
ADO today for some of the methods of the Recordset object.
1, AddNew method
Creates a new record that can update the Recordset object.
Recordset. AddNew FieldList, Values
FieldList Optional. A single name, group name, or ordinal position of a field in a new record.
Values are optional. A single or set of values for a field in a new record. If the Fields is an array, then Values must also be arrays with the same number of members, otherwise an error will occur. The order of the field names must match the order of the field values in each array.

We are generally
Rs.addnew
RS ("xx") =xx
RS ("xx") =xx
Rs.update
Note that the AddNew method without parameters can be set to adEditAdd by invoking the EditMode property in Immediate updating mode (the provider will immediately write the change to the underlying data source when the Update method is invoked). The provider caches changes to any field values locally. Call the Update method to pass a new record to the database and reset the EditMode property to adEditNone. If the Fields and values parameters are passed, ADO immediately passes the new record to the database (no need to call Update), and the EditMode property value has not changed (adEditNone).
Perhaps you will be asked to use the AddNew method of ADO in ASP and to use the "Insert into ..." statement directly and differently? That's a better way? A: ADO's AddNew method only encapsulates "Insert into" statement, so when manipulating large amounts of data, direct use of SQL statements will greatly speed up access to data because he reduces the "translation" Time of ADO.

2. Delete method
Deletes the current record or group of records.
Recordset. Delete AffectRecords

AffectRecords the AffectEnum value to determine the number of records affected by the Delete method, which can be one of the following constants.
adAffectCurrent default. Deletes only the current record.
adAffectGroup deletes the record that satisfies the current Filter property setting. To use this option, you must set the Filter property to one of the valid predefined constants.
Adaffectall deletes all records.
adAffectAllChapters deletes all subset records.
Use immediate update mode to delete immediately in the database, otherwise the record will be marked for deletion from the cache, and the actual deletion will be made when the Update method is called.

3. Update method
Save all changes made to the current record of the Recordset object
Recordset. Update Fields, Values
Fields Optional. Variant type, representing a single name, or Variant array, representing the name and ordinal position of the field (one or more) that needs to be modified.
Values are optional. Variant type, representing a single value, or Variant array representing the field (single or multiple) values in the new record.
If you want to cancel any changes to the current record or discard the newly added records, you must call the CancelUpdate method.

4, CancelUpdate method
Recordset. CancelUpdate
Use the CancelUpdate method to cancel any changes made to the current record or to discard newly added records. Changes made to the current record or new record cannot be undone after the Update method is called, and if a new record is added when the CancelUpdate method is invoked, the current record before the call to AddNew becomes the current record again. If you have not changed the current record or added a new record, calling the CancelUpdate method will produce an error.

5, Find method
Searches the recordset for records that meet the specified criteria. If the criteria are met, the recordset location is set on the found record, otherwise the location is set at the end of the recordset.
Find (criteria, skiprows, searchdirection, start)
The criteria string that contains the statement that specifies the column name, comparison operator, and value for the search.
SkipRows optional, Long value with a default value of zero, which specifies the offset of the current row or start bookmark to begin the search.
SearchDirection an optional SearchDirectionEnum value that specifies whether the search should start with the current row or the next valid row. The value can be Adsearchforward or

Adsearchbackward. Whether the search ends at the beginning or end of the recordset is determined by the searchdirection value.
Start optional, Variant bookmark, used as the starting position for the search.
The criteria "comparison operator" can be ">" (Greater Than), "<" (less than), "=" (equals), ">=" (greater than or equal to), "<=" (less than or equal to), "<>"

(not equal to) or "like" (Pattern matching). The values in the criteria can be strings, floating-point numbers, or dates. String values are delimited by single quotes (such as "state = ' WA '").

Date values are delimited by "#" (digital notation) (such as "Start_date > #7/22/97#").
It should be noted that find is not supported for multiple fields. But it can be implemented with filter. "Name= ' abc" and "City= ' sh '" are not allowed

6. Move method
Move the position of the current record in the Recordset object
Recordset. Move NumRecords, Start
NumRecords a signed long integer expression that specifies the number of records to move in the current record position.
Start Optional, string or variant type, for calculating bookmarks. can also be one of the following values:
Adbookmarkcurrent default. Start with the current record.
Adbookmarkfirst begins with the first record.
Adbookmarklast begins with the tail record.
It is to be noted that:
(1) If the NumRecords parameter is greater than 0, the current record position is moved forward (to the end of the recordset). If the numrecords is less than 0, the current record position is moved backward (to the beginning of the Recordset).
(2) Calling the Move method from an empty Recordset object generates an error.
(3) If the move call moves the current record position to the first record, ADO places the current record before the first record of the recordset (BOF is True). Attempting to move backwards when the BOF property is True causes an error, and if the move call moves the current record position to the tail record, ADO places the current record after the end record of the recordset (EOF is True). Attempting to move forward when the EOF property is already True will result in an error.

7, MoveFirst, MoveLast, MoveNext and MovePrevious methods
Moves to the first, last, next, or previous record in the specified Recordset object and makes the record the current record.
Recordset. {MoveFirst | MoveLast | MoveNext | MovePrevious}
It is to be noted that:
(1) Use the MoveNext method to move the current record forward one record (to the bottom of the Recordset). If the last record is the current record and the MoveNext method is invoked, ADO sets the current record to the end of the recordset (EOF is True). Attempting to move forward when the EOF property is already True generates an error.
(2) Use the MovePrevious method to move the current record position back one record (to the top of the Recordset). The Recordset object must support backward cursor movement, otherwise the method call will produce an error. If the first record is the current record and the MovePrevious method is invoked, ADO sets the current record before the first record of the recordset (BOF is True). When the BOF property is True, moving backwards will produce an error.

8. Clone method
Creates the same replication Recordset object as an existing Recordset object. Optionally specify that the copy is read-only.
Set rstduplicate = Rstoriginal.clone
Rstduplicate An object variable that identifies the replication Recordset object being created.
Rstoriginal An object variable that identifies the Recordset object to be replicated.
Use the Clone method to create multiple copies of a Recordset object, which is useful for keeping multiple current records in a given group of records. Using the Clone method is much more effective than creating and opening a new Recordset object with the same definition as the initial definition.
Other words
Rs.Open exec,conn,1,1
Rs2.open exec,conn,1,1
It should be so rewritten.
Rs.Open exec,conn,1,1
Rs2=rs.clone

It is to be noted that:
(1) The current record of the newly created replica will be set as the head record.
(2) Closing the original Recordset does not close its copy, and closing a copy will not close the original recordset or any other copy.

9. Close method
Closes the open object and any related objects.
Object. Close
It is to be noted that:
(1) Use the Close method to shut down the Recordset object to free all associated system resources. Closing an object does not remove it from memory, you can change its property settings and

Open again thereafter. To completely remove an object from memory, set the object variable to nothing.
(2) If you are editing in immediate update mode, calling the Close method generates an error and calls the update or CancelUpdate method first.


10, the Open method, why the last say this, because the previous property methods are not clear, we will not understand the CursorType parameter
Recordset. Open Source, ActiveConnection, CursorType, LockType, Options
The Recordset object can connect to the command object through the Source property. The source parameter can be a command object name, a section of SQL command, a specified data table name, or a stored Procedure. If this argument is omitted, the system takes the source property of the Recordset object. ActiveConnection

The Recordset object can be connected through the ActiveConnection property



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.