액티브엑스 데이터 오브젝트
위키백과 ― 우리 모두의 백과사전.
액티브엑스 데이터 오브젝트(ADO)는 데이터 원본에 접근하기 위해 마이크로소프트 표준으로 제작된 컴포넌트 오브젝트 모델 객체들의 모임이자, 프로그래밍 인터페이스(API)이다.
목차 |
[편집] 들어가며
프로그래밍 언어와 OLE DB 사이의 계층을 제공함으로써 개발자가 데이터 추가 방법을 알지 않더라도 데이터에 접근하는 프로그램을 짤 수 있게 도와 준다. 다만 연결을 위한 데이터베이스에 대해서는 알고 있어야 한다. ADO를 사용할 때에는 비록 사용자가 ADO를 사용하여 임의의 SQL 명령어를 실행할 수 있다 하더라도 데이터베이스에 접근하기 위해 SQL의 지식이 요구되지는 않는다.
[편집] 종류
ADO는 몇 가지 최상위 객체로 이루어져 있다:
- 주요 객체
- 연결 객체(Connection Object): 특정 DBMS(데이터베이스 관리 시스템)이나 다른 데이터 소스에 대한 연결을 설정한다. 또한 데이터베이스에 쿼리를 보낼 수도 있다.
- 레코드셋 객체(Recordset Object): 레코드 그룹인 결과 응답이 들어 있다.
- 명령 객체(Command Object): SQL 명령어를 대표한다.
- 일반 객체
- 레코드 객체(Record Object)
- 스트림 객체(Stream Object)
- 오류 객체(Error Object)
- 필드 객체(Field Object)
- 변수 객체(Parameter Object)
- 속성 객체(Property Object)
[편집] 기본 사용법
ADO를 사용하여 데이터에 접근하고 이용하려면 다음과 같은 기본 과정을 밟아야 한다:
- 데이터베이스에 연결할 연결 객체를 하나 만든다.
- 데이터를 받기 위해 레코드셋 객체를 하나 만든다.
- 연결을 연다.
- 연결을 열고 원하는 테이블 이름이나 SQL 명령을 open 함수로 통과시킴으로써 레코드셋을 놓는다.
- 패치(fetch) 데이터 위에서 검색 및 처리를 한다.
- Update나 UpdateBatch 메써드(method)를 사용하여 데이터에 대한 변경 사항을 확인한다.
- 레코드셋을 닫는다.
- 연결을 닫는다.
[편집] ASP의 예
ADO를 사용한 예:
dim myconnection, myrecordset, name
set myconnection = server.createobject("ADODB.Connection")
set myrecordset = server.createobject("ADODB.Recordset")
myconnection.open mydatasource
myrecordset.open "Phonebook", myconnection
myrecordset.find "PhoneNumber = '555-5555'"
name = myrecordset.fields.item("Name")
myrecordset.close
set myrecordset = nothing
set myconnection = nothing
레코드셋 객체 기능을 사용하지 않고 SQL을 사용한 ASP 코드로는 다음과 같다.
dim myconnection, myrecordset, name
set myconnection = server.createobject("ADODB.connection")
myconnection.open mydatasource
set myrecordset = myconnection.execute("SELECT Name FROM Phonebook WHERE PhoneNumber = '555-5555'")
name = myrecordset(0)
[편집] VBA의 예
Dim myconnection as new ADODB.Connection
Dim myrecordset as new ADODB.Recordset
Set myconnection = CurrentProject.AccessConnection
myrecordset.Open "items", myconnection, adOpenKeyset, adLockOptimistic, adCmdTable
myrecordset.find "item_code = 'GI8293-23'"
if (not myrecordset.EOF) 'If the specified criteria cannot be satisfied, then the current record is EOF
myrecordset!item_name = "My New Item"
end if
myrecordset.update 'Actually commit the update to the data source
myrecordset.close
myconnection.close
[편집] 소프트웨어 지원
ADO는 VBA와 VBA for Office에서 지원을 받을 수 있다.
[편집] 같이 보기
[편집] 바깥 고리
![]() |
이 글은 컴퓨터에 관한 토막글입니다. 서로의 지식을 모아 알차게 문서를 완성해 갑시다. |


