ADO 레코드 집합 개체



이 예제에서는 GetRows 메서드를 사용하는 방법을 보여줍니다.


레코드 집합 개체

ADO Recordset 개체는 데이터베이스 테이블의 레코드 집합을 보유하는 데 사용됩니다. Recordset 개체는 레코드와 열(필드)로 구성됩니다.

ADO에서 이 개체는 가장 중요하고 데이터베이스에서 데이터를 조작하는 데 가장 자주 사용되는 개체입니다.


ProgID

set objRecordset=Server.CreateObject("ADODB.recordset")

Recordset을 처음 열 때 현재 레코드 포인터는 첫 번째 레코드를 가리키고 BOF 및 EOF 속성은 False입니다. 레코드가 없으면 BOF 및 EOF 속성이 True입니다.

Recordset 개체는 두 가지 유형의 업데이트를 지원할 수 있습니다. 

  • 즉시 업데이트 - Update 메서드를 호출하면 모든 변경 사항이 즉시 데이터베이스에 기록됩니다.
  • 일괄 업데이트 - 공급자는 여러 변경 사항을 캐시한 다음 UpdateBatch 메서드를 사용하여 데이터베이스로 보냅니다.

ADO에는 4가지 다른 커서 유형이 정의되어 있습니다.

  • 동적 커서 - 다른 사용자의 추가, 변경 및 삭제를 볼 수 있습니다.
  • 키 집합 커서 - 다른 사용자가 추가한 내용을 볼 수 없고 다른 사용자가 삭제한 레코드에 대한 액세스를 방지한다는 점을 제외하고는 동적 커서와 같습니다. 다른 사용자가 변경한 데이터는 계속 볼 수 있습니다.
  • 정적 커서 - 데이터를 찾거나 보고서를 생성하는 데 사용할 레코드 집합의 정적 복사본을 제공합니다. 다른 사용자의 추가, 변경 또는 삭제는 볼 수 없습니다. 이것은 클라이언트 측 Recordset 개체를 열 때 허용되는 유일한 유형의 커서입니다.
  • 앞으로 전용 커서 - 레코드 집합을 통해 앞으로만 스크롤할 수 있습니다. 다른 사용자의 추가, 변경 또는 삭제는 볼 수 없습니다. 

커서 유형은 CursorType 속성 또는 Open 메서드의 CursorType 매개 변수로 설정할 수 있습니다.

참고: 모든 공급자가 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

Fields 컬렉션의 속성

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)
or
itemfields=rs.Fields.Item("Name")


속성 컬렉션의 속성

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)
or
itemprop=rs.Properties.Item("Name")