ออบเจ็กต์ชุดระเบียน ADO
ตัวอย่าง
ตัวอย่างนี้สาธิตวิธีการใช้เมธอด GetRows
วัตถุชุดระเบียน
ออบเจ็กต์ ADO Recordset ใช้เพื่อเก็บชุดระเบียนจากตารางฐานข้อมูล วัตถุชุดระเบียนประกอบด้วยระเบียนและคอลัมน์ (เขตข้อมูล)
ใน ADO ออบเจ็กต์นี้มีความสำคัญที่สุดและใช้บ่อยที่สุดในการจัดการข้อมูลจากฐานข้อมูล
ProgID
set objRecordset=Server.CreateObject("ADODB.recordset")
เมื่อคุณเปิดชุดระเบียนครั้งแรก ตัวชี้ระเบียนปัจจุบันจะชี้ไปที่ระเบียนแรก และคุณสมบัติ BOF และ EOF จะเป็นเท็จ หากไม่มีบันทึก คุณสมบัติ BOF และ EOF จะเป็น True
ออบเจ็กต์ชุดระเบียนสามารถรองรับการอัปเดตได้สองประเภท:
- อัปเดตทันที - การเปลี่ยนแปลงทั้งหมดจะถูกเขียนลงในฐานข้อมูลทันทีเมื่อคุณเรียกใช้เมธอด Update
- การ อัปเดต แบบกลุ่ม - ผู้ให้บริการจะแคชการเปลี่ยนแปลงหลายรายการแล้วส่งไปยังฐานข้อมูลด้วยวิธี UpdateBatch
ใน ADO มีการกำหนดประเภทเคอร์เซอร์ที่แตกต่างกัน 4 ประเภท:
- เคอร์เซอร์แบบไดนามิก - ให้คุณเห็นการเพิ่มเติม การเปลี่ยนแปลง และการลบโดยผู้ใช้รายอื่น
- เคอร์เซอร์ชุดคีย์ -เช่นเดียวกับเคอร์เซอร์แบบไดนามิก ยกเว้นว่าคุณไม่สามารถมองเห็นการเพิ่มเติมจากผู้ใช้รายอื่น และจะป้องกันการเข้าถึงเรกคอร์ดที่ผู้ใช้รายอื่นได้ลบไป การเปลี่ยนแปลงข้อมูลโดยผู้ใช้รายอื่นจะยังคงปรากฏให้เห็น
- เคอร์เซอร์แบบคงที่ - จัดเตรียมสำเนาสแตติกของชุดระเบียนเพื่อให้คุณใช้เพื่อค้นหาข้อมูลหรือสร้างรายงาน การเพิ่มเติม การเปลี่ยนแปลง หรือการลบโดยผู้ใช้รายอื่นจะไม่ปรากฏให้เห็น นี่เป็นเคอร์เซอร์ชนิดเดียวที่อนุญาตเมื่อคุณเปิดวัตถุ Recordset ฝั่งไคลเอ็นต์
- เคอร์เซอร์ไปข้างหน้าเท่านั้น - ให้คุณเลื่อนไปข้างหน้าผ่านชุดระเบียนเท่านั้น การเพิ่มเติม การเปลี่ยนแปลง หรือการลบโดยผู้ใช้รายอื่นจะไม่ปรากฏให้เห็น
ประเภทเคอร์เซอร์สามารถตั้งค่าได้ตามคุณสมบัติ CursorType หรือโดยพารามิเตอร์ CursorType ในเมธอด Open
หมายเหตุ:ผู้ให้บริการบางรายอาจไม่สนับสนุนเมธอดหรือคุณสมบัติทั้งหมดของอ็อบเจ็กต์ Recordset
คุณสมบัติ
Property | Description |
---|---|
AbsolutePage | Sets or returns a value that specifies the page number in the Recordset object |
AbsolutePosition | Sets or returns a value that specifies the ordinal position of the current record in the Recordset object |
ActiveCommand | Returns the Command object associated with the Recordset |
ActiveConnection | Sets or returns a definition for a connection if the connection is closed, or the current Connection object if the connection is open |
BOF | Returns true if the current record position is before the first record, otherwise false |
Bookmark | Sets or returns a bookmark. The bookmark saves the position of the current record |
CacheSize | Sets or returns the number of records that can be cached |
CursorLocation | Sets or returns the location of the cursor service |
CursorType | Sets or returns the cursor type of a Recordset object |
DataMember | Sets or returns the name of the data member that will be retrieved from the object referenced by the DataSource property |
DataSource | Specifies an object containing data to be represented as a Recordset object |
EditMode | Returns the editing status of the current record |
EOF | Returns true if the current record position is after the last record, otherwise false |
Filter | Sets or returns a filter for the data in a Recordset object |
Index | Sets or returns the name of the current index for a Recordset object |
LockType | Sets or returns a value that specifies the type of locking when editing a record in a Recordset |
MarshalOptions | Sets or returns a value that specifies which records are to be returned to the server |
MaxRecords | Sets or returns the maximum number of records to return to a Recordset object from a query |
PageCount | Returns the number of pages with data in a Recordset object |
PageSize | Sets or returns the maximum number of records allowed on a single page of a Recordset object |
RecordCount | Returns the number of records in a Recordset object |
Sort | Sets or returns the field names in the Recordset to sort on |
Source | Sets a string value or a Command object reference, or returns a String value that indicates the data source of the Recordset object |
State | Returns a value that describes if the Recordset object is open, closed, connecting, executing or retrieving data |
Status | Returns the status of the current record with regard to batch updates or other bulk operations |
StayInSync | Sets or returns whether the reference to the child records will change when the parent record position changes |
วิธีการ
Method | Description |
---|---|
AddNew | Creates a new record |
Cancel | Cancels an execution |
CancelBatch | Cancels a batch update |
CancelUpdate | Cancels changes made to a record of a Recordset object |
Clone | Creates a duplicate of an existing Recordset |
Close | Closes a Recordset |
CompareBookmarks | Compares two bookmarks |
Delete | Deletes a record or a group of records |
Find | Searches for a record in a Recordset that satisfies a specified criteria |
GetRows | Copies multiple records from a Recordset object into a two-dimensional array |
GetString | Returns a Recordset as a string |
Move | Moves the record pointer in a Recordset object |
MoveFirst | Moves the record pointer to the first record |
MoveLast | Moves the record pointer to the last record |
MoveNext | Moves the record pointer to the next record |
MovePrevious | Moves the record pointer to the previous record |
NextRecordset | Clears the current Recordset object and returns the next Recordset object by looping through a series of commands |
Open | Opens a database element that gives you access to records in a table, the results of a query, or to a saved Recordset |
Requery | Updates the data in a Recordset by re-executing the query that made the original Recordset |
Resync | Refreshes the data in the current Recordset from the original database |
Save | Saves a Recordset object to a file or a Stream object |
Seek | Searches the index of a Recordset to find a record that matches the specified values |
Supports | Returns a boolean value that defines whether or not a Recordset object supports a specific type of functionality |
Update | Saves all changes made to a single record in a Recordset object |
UpdateBatch | Saves all changes in a Recordset to the database. Used when working in batch update mode |
กิจกรรม
หมายเหตุ: คุณไม่สามารถจัดการเหตุการณ์โดยใช้ VBScript หรือ JScript (เฉพาะภาษา Visual Basic, Visual C++ และ Visual J++ เท่านั้นที่สามารถจัดการเหตุการณ์ได้)
Event | Description |
---|---|
EndOfRecordset | Triggered when you try to move to a record after the last record |
FetchComplete | Triggered after all records in an asynchronous operation have been fetched |
FetchProgress | Triggered periodically in an asynchronous operation, to state how many more records that have been fetched |
FieldChangeComplete | Triggered after the value of a Field object change |
MoveComplete | Triggered after the current position in the Recordset has changed |
RecordChangeComplete | Triggered after a record has changed |
RecordsetChangeComplete | Triggered after the Recordset has changed |
WillChangeField | Triggered before the value of a Field object change |
WillChangeRecord | Triggered before a record change |
WillChangeRecordset | Triggered before a Recordset change |
WillMove | Triggered before the current position in the Recordset changes |
ของสะสม
Collection | Description |
---|---|
Fields | Indicates the number of Field objects in the Recordset object |
Properties | Contains all the Property objects in the Recordset object |
คุณสมบัติของ The Fields Collection
Property | Description |
---|---|
Count | Returns the number of items in the fields collection. Starts at zero.
Example: countfields=rs.Fields.Count |
Item(named_item/number) | Returns a specified item in the fields collection.
Example: itemfields=rs.Fields.Item(1) |
คุณสมบัติของคอลเลกชันคุณสมบัติ
Property | Description |
---|---|
Count | Returns the number of items in the properties collection. Starts at zero.
Example: countprop=rs.Properties.Count |
Item(named_item/number) | Returns a specified item in the properties collection.
Example: itemprop = rs.Properties.Item(1) |