ADO中一共提供了九个对象和四个集合
对象、集合 |
描述 |
Connection object |
代表了与数据源的唯一会话,即已经打开的、与数据源的连接。 |
Command object |
Command对象定义了将对数据源执行的命令; |
Recordset object |
可用来存储一个TABLE中所有的记录,也用来存储某个命令的执行结果,如一个查询语句的执行结果。整个Recordset 对象由records (rows)和fields (columns)组成. |
Record object |
代表某一行的数据(也就是用来表示一个record) |
Stream object |
代表一个二进制或者文本数据流; |
Parameter object(和参数化的查询过程相关) |
代表一个与Command对象相关的参数或者变量;该Command对象是基于参数化查询或存贮的过程。 |
Field object |
代表一列数据 |
Property object |
代表ADO的某一特性;具体依赖于提供者; |
Error object |
某一次操作的所产生的错误的详细的信息 |
Fields collection |
Contains all the Field objects of a Recordset or Record object. |
Properties collection |
Contains all the Property objects for a specific instance of an object. |
Parameters collection |
Contains all the Parameter objects of a Command object. |
Errors collection |
Contains all the Error objects created in response to a single provider-related failure. |
下面贴出MSDN中所给出的一段VB代码,用以说明几个基本对象的作用,不懂VB没关系,我加了一部分注释。
1 ' Define a Connection object
2 Dim oConn As ADODB.Connection
3
4 ' Define a Recordset object
5 Dim oRs As ADODB.Recordset
6
7 ' Define a String object used to set the property of Connection object
8 Dim sConn As String
9
10 ' Define a String object used to store SQL query command
11 Dim sSQL as String
12
13 ' Set the ConnectionString property
14 sConn = "Provider='SQLOLEDB';Data Source='MySqlServer';" & _
15 "Initial Catalog='Northwind';Integrated Security='SSPI';"
16
17 ' Open a connection.
18 Set oConn = New ADODB.Connection
19 oConn.Open sConn
20
21 ' Make a query over the connection.
22 ' &_ is used to indicate that the next line is a continuation of the previous line
23 sSQL = "SELECT ProductID, ProductName, CategoryID, UnitPrice " & _
24 "FROM Products"
25
26 ' execute the query command
27 Set oRs = New ADODB.Recordset
28 oRs.Open sSQL, oConn, adOpenStatic, adLockBatchOptimistic, adCmdText
29
30 MsgBox oRs.RecordCount
31
32 ' Close the connection.
33 oConn.Close
34 Set oConn = Nothing