ADO


ADO (正體)

Free Web Hosting with Website Builder

微软公司ADO (ActiveX Data Objects) 是一个用于存取数据源的COM组件。它提供了编程语言和统一数据访问方式OLE DB的一个中间层。允许开发人员编写访问数据的代码而不用关心数据库是如何实现的,而只用关心到数据库的连接。访问数据库的时候,关于SQL的知识不是必要的,但是特定数据库支持的SQL命令仍可以通过ADO中的命令对象来执行。

目录

架构

ADO被设计来继承微软早期的数据访问对象层,包括RDO (Remote Data Objects) 和DAO(Data Access Objects)。ADO在1996年冬被发布。

ADO包含一些顶层的对象:

  • 连接(Connection),代表到数据库的连接
  • 记录集(Recordset),代表数据库记录的一个集合
  • 命令(Command),代表一个SQL命令
  • 记录(Record),代表数据的一个集合
  • 流(Stream),代表数据的顺序集合
  • 错误(Error),代表数据库访问中产生的意外
  • 字段(Field),代表一个数据库字段
  • 参数(Parameter),代表一个SQL参数
  • 属性(Property),保存对象的信息

ADO组件的使用需要利用支持COM的高级语言,例如ASP中的VBScript或者Visual Basic,甚至微软的竞争对手Borland的产品Delphi,,现在也支持使用ADO来访问数据库。

在新的编程框架.NET Framework中, 微软也提供了一个面向Internet的版本的ADO,称为ADO.NET。其对象模型和传统ADO差别很大。

基本功能

使用 ADO 存取资料的一些基本步骤 :

  1. 生成一个连结物件去连结数据库(Create a connection object to connect to the database.)
  2. 生成一个recordset物件来取得资料(Create a recordset object in order to receive data in.)
  3. 开启一个连结(Open the connection)
  4. 在recordset中完成SQL语法的描述(Populate the recordset by opening it and passing the desired table name or SQL statement as a parameter to open function.)
  5. Do all the desired searching/processing on the fetched data.
  6. 确定改变资料(Commit the changes you made to the data (if any) by using Update or UpdateBatch methods.)
  7. 关闭recordset(Close the recordset)
  8. 关闭连结(Close the connection)

ASP 范例

下列的 ASP 范例使用 ADO 于 "Phonebook" 表中选取 "Name" 字段, 并设定 "PhoneNumber" 等于 "555-5555"。

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

这相当于下列的 ASP code, 以 plain SQL 取代 Recordset object:

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)

参见

外部链接


数据库管理系统(DBMS)查看  讨论  编辑  历史 )

概念
数据库 • 数据库模型 • 资料库储存结构 • 关系模型 • 分布式资料库 • ACID • NULL值
关系数据库 • 关系代数 • 关系演算 • 资料库正规化 • 参照完整性 • 关系数据库管理系统 
主键 • 外来键 • 代理主键 • 超键值 • 候选键 

资料库物件
触发程序 • 检视表 • 资料表 • 指标 • 交易记录档 • 交易 • 数据库索引 
预存程序 • 资料库分割

SQL
分类:资料定义语言 • 资料操纵语言 • 资料控制语言
指令:SELECT • INSERT • UPDATE • MERGE • DELETE • JOIN • UNION • CREATE • DROP • Begin work • COMMIT • ROLLBACK • TRUNCATE • ALTER
安全: SQL Injection • 参数化查询

数据库管理系统的实施

实施类型
关联式资料库 • 档案型资料库 • Deductive • 维度化资料库 • 阶层式 • 对象数据库 • 物件关联式资料库 • Temporal • XML资料库

数据库产品
对象型 (对比) • 关系型 (对比)

数据库成分
查询语言 • 查询优化器 • 查询计划 • ODBC • JDBC • OLE DB







Why are we here?
All text is available under the terms of the GNU Free Documentation License
This page is cache of Wikipedia. History