荔园在线

荔园之美,在春之萌芽,在夏之绽放,在秋之收获,在冬之沉淀

[回到开始] [上一篇][下一篇]


发信人: baty (新一代懒人), 信区: Database
标  题: 关于ADO
发信站: BBS 荔园晨风站 (Mon Mar 12 22:14:43 2001), 转信

【 以下文字转载自 baty 的信箱 】
【 原文由 baty.bbs@argo.zsu.edu.cn 所发表 】
发信人: CMusic (音韵), 信区: Database
标  题: 关于ADO
发信站: 逸仙时空 Yat-sen Channel (Wed Nov  1 00:18:03 2000), 站内信件

ActiveX Data Objects (ADO) Overview

After reading this chapter, you will be able to do the following:

昄ist the advantages of using ActiveX Data Objects (ADO) for database
access 旸
how to create ActiveX Data Objects by using Visual Basic, Visual Basic
Script,
DAO (Data Access Objects), and RDO (Remote Data Objects)


------------------------------------------------------------------------



Why ADO Is So Cool

ADO (ActiveX Data Objects) is a technology that can be used by Web
page develop
preferences, past usage history, or up-to-the-minute news. Database
application
up to date based on real information from the same sources that drive
current b.

ADO is a technology meant for application and Web-site developers with
modest p
advanced features grow with any project. ADO couples ease-of-use with
a full ra.

ADO is consistent, no matter what database program is actually used to
store th
Microsoft Access or Microsoft FoxPro or resides in servers from
companies like .

ADO is cross language. This means that besides being consistent across
multiple
be easily transferred to another. Programmers developing commercial
products wi
JavaScript, or Java. The product they use is the same in each case. A
company c
environment.

ADO is available today on the platforms you use. ActiveX Data Objects
are acces
running on Intel, DEC Alpha, and PowerPC, in addition to any platform
governed
way, any platform supporting a modern Web browser can automatically take
 advant
order products.




------------------------------------------------------------------------



The Benefits of Basing ActiveX Data Objects on Microsoft's COM

COM is advantageous because it enforces an agreement between software
producers
Many separate objects can share the same definition of a single
interface, allo
interfaces gives you a simple, consistent way to customize software.
Functions .

COM objects are multifaceted. They aren't restricted to a single set
of functio
another. Similarly, you're free to choose among the interfaces supported
 by a c.

COM objects are easily distributed. They automatically gain the
ability to be u
objects. They can be passed back and forth through function calls as
easily as
or remote, your code is exactly the same.


------------------------------------------------------------------------





------------------------------------------------------------------------



The Benefits of Basing ActiveX Data Objects on Microsoft's COM

COM is advantageous because it enforces an agreement between software
producers
Many separate objects can share the same definition of a single
interface, allo
interfaces gives you a simple, consistent way to customize software.
Functions .

COM objects are multifaceted. They aren't restricted to a single set
of functio
another. Similarly, you're free to choose among the interfaces supported
 by a c.

COM objects are easily distributed. They automatically gain the
ability to be u
objects. They can be passed back and forth through function calls as
easily as
or remote, your code is exactly the same.


------------------------------------------------------------------------







The ADO Model

The ADO model defines a hierarchy of programmable objects that can be
used by t
hierarchy; each box represents an object, and each line represents a
direct ass.

<图片>

Figure 8.1.

A hierarchy chart.

The term object has many different meanings, depending on who you ask.
In the w
object stores, and other merging ideas between programming and databases
 that m
object-oriented programming languages, such as C++, Smalltalk, and yes,
 even Vi.

An object is best understood as a logical association between program
variables
number. A function declared in the same language is expected to take
an action,.

<图片>

Figure 8.2.

A "generic" object with its associated variables and functions.

An object is more than just a variable, or many variables, and its' more
 than j
useful.

For example, variables and functions organized together into an object
might re
canceling the reservation might be considered some of the object's
functions. T
the programmer wants to work with 10 reservations at once, for instance,
 it's e
need look no further than the object's description. Instead of needing
to under
over four weeks and three continents. Good organization isopertiesA
collection
objectErrorsA collection of multiple Error objectsErrorAn individual
Error objet

The Connection object can be used to establish a dedicated line of
communicatio
object is a telephone call. The act of creating a Connection object is
just lik
open line to the database, requesting and updating information.

The Command object can be used to specify a database query. Often this
query is
accept requests written with this language. ADO allows the programmer to
 use wh
property. Later, when the command is executed, the query is sent to
the databas.

line of code.



Doing It Yourself

There are, however, very good reasons to do the work your self. Both
Connection
affect how the query is performed, how the server produces results,
and how upd
isn't possible, however, if you leave the work of creating the
connection to th.



Taking Advantage of Shared Command Objects

Other advanced features, discussed later in this book, give equally
compelling
11, "Transactions and the ADO Connection" will show you how. This
ability gives
share connections across multiple Web page hits, for the same client
or for man
placed on the database snd how to insert scripting code into HTML pages.
 The sc
tags and clicks a button, the scripting code takes over. The code you
added is .

If you're already familiar with Visual Basic, then Visual Basic Script
is by al
look practically identical to the code you would have written using
Visual Basi
inside an HTML document. Embedded between a pair of HTML tags, actual
code lies.

The only real difference between using ADO in Visual Basic Script and
using it
it, which requires you to use a Dim statement, of course.



Visual Basic and the Dim Statement

The Dim statement was introduced in Basic long ago, during the
dinosaur years w
variable x to contain 11 elements, 0 through 10." Later, Microsoft
developed Ba
floating-point number. Likewise, Dim x(10) As Integer would declare an
array of
up. In the dinosaur years, if you wanted to use a string, you had to add
 a suff.

Alas, Visual Basic came along and extended Basic once again. No longer
are you
Automation/ActiveX servers, can appear simply as normal, built-in
primitives. A
immediately begin using your new data type or object. To declare a
variable of .

In Visual Basic, declaring ActiveX Data Objects is just as simple. The
followin:

Dim rs as new Recordset

Dim cn as New Connection

Dim cm as New Command

This syntax for declaring objects is extremely useful when yriables
are objects
it. Instead of being allowed to use only integers with variables
declared as In
the middle, it can be a String, or a Single, or even a Recordset. This
change i
declare individual variables as Variant and gain all the same advantages
 of VBS
custom data type.



Using an Alternative to the Dim Statement

All this preceding discussion means you won't be using a Dim statement
to decla
Visual Basic.

The CreateObject() function was originally supplied in Visual Basic as a
 means
its sole parameter. A programmer could, if he wanted, change the
custom type he
this function as the sole object-creation mechanism because it was
both powerfu
Variant can quite easily take on the appearance of an Object, so
VBScript was f.

Creating an ActiveX Data Object in VB Script is as simple as calling the
 Create:

Set rs = CreateObject("ADODB.Recordset")

Set cn = CreateObject("ADODB.Connection")

Set cm = CreateObject("ADODB.Command")

Make sure you notice the prefix ADODB used in each of the CreateObject()
 functi
the object. Pronounced "PROG-I-D," meaning "Program ID," this name is
used by t
release of ActiveX Data Objects, affectionately named ADODB, is designed
 to be
ADODB is a component that's included with Internet Information Server
3.0 or hi
library name is optional when declaring a variable typed as an object.
The libr
the object from the operating system's registry.



ADO and Active Server Pages

Active Server Pages is a technology introduced by Microsoft in
Internet Informa
other means to customize Web pages, none is more elegant and powerful
than Acti
directly to the Web page and inserted precisely between the HTML
instructions t
obfuscated output the programs generate, with Active Server Pages, you
can put
automatically direct the changes to the document when the code is
executed on t.

With Active Server Pages, the code you add to the HTML documents is
not unlike
scripting code that's executed after the Web page is downloaded from the
 Web se
and Active Server Pages has added this same capability to Internet
Information
is transferred across the network. The ability to use the exact same
scripting
application.



Customizing with Scripting Code

It's also possible to use client-side scripting to customize a Web
page after i
page has finished transferring from the server. This code could actually
 alter
be the primary technique because it has many drawbacks. With tools
such as Acti.

Web pages with extensive customization code are much larger than pages
that are
Customization on the server allows the workload to be placed on the
server, not
streamlined as a non-customized page.

The most important use of server-side scripting is, perhaps, the one
that's equ
Web site or the user accessing it. There may be reasons to add tricks
such as r
customize themselves based on user preferences, history of previous
visits or p.

One great advantage to customizing with Active Server Pages is that
the Web ser
protect computers in a company from the wild, unguarded chaos of the
global Int
corporate network is connected to the Internet in the first place.



Reducing the Risk to Database Servers

Database servers, however, are often considered too critical to a
company's exi
database server, so they can access the databases directly. This
restriction is
distributed networks, such as the Internet, and databases are often
designed wi
mid-step. Proprietary protocols are often devised to reduce these
risks even fu
directly to the global Internet, it's unlikely they could be
communicated with.

Many companies, like Microsoft, are trying to come up with ways to
ensure relia
bridging the gap between local area networks and distributed networks.
For onli.

There are trade-offs, however, when choosing client-side tools such as
the Adva
guarantee their hardware is of a certain type and above a certain par,
and thei
general audience with a widely diverging set of computer hardware and
software?
scripting code with direct access to secure databases, transmit as
pure HTML do.



Using Active Server Pages

This discussion on database access, of course, brings you back to
ActiveX Data
by altering the HTML instructions within it. ADOs can be integrated into
 Active
a mechanism of introducing ADO as VBScript alone.

The CreateObject() function is available in the scripting code
embedded in the
These objects aren't available to scripting code running on the client;
 they're
these built-in objects extensively.

The following statement written in VBScript for Active Server Pages
demonstrate:

<% Set rs = Server.CreateObject("ADODB.Recorticular database in mind. It
 has a
Connectivity, is one such open standard.

Originating from Microsoft, ODBC has become the recognized standard
for providi
directly access their database technology through a single consistent,
common i
technology. ODBC is an API (application programming interface), a set of
 standa
a good interface for supplying data, it left a lot to be desired when
used as a.

To solve the ease-of-use problem with ODBC once and for all, Microsoft
invented
cube-shaped box known as Microsoft Visual Basic Enterprise Edition.
RDO had its
wasn't a clean match to ODBC. Altering the DAO model would ruin its
attractiven
what the Enterprise Edition was all about. Change was in the wind, and
the comm
that left it strongly positioned as a database server. For the Fox
database eng
as a primary mechanism to deliver its goods to the consumers.

There had never been a more confusing time for Microsoft databases or
for progr
the JET database engine? Not all that functionality was available
through ODBC.
It let each product continue on its own way, expanding in directions
more favor.

Microsoft knew that something larger loomed on the horizon, something
that woul
needed a fresh dose of simplification for the average programmer.

The DAO team and the RDO team joined forces, determined to settle
differences a
act as a kinder, gentler way of programming. The database development
companies
OLE-DB directly, but end-user programmers杢hose building corporate
database app
of programming time. Getting up and running with ADO would be as
simple as crea.



Summary

This chapter has given you an overview of ADO, ActiveX Data Objects, and
 discus
mechanism for creating each ADO object using Visual Basic and Visual
Basic Scri
a complete synopsis of the advantages gained by using ActiveX Data
Objects, Vis
easy-to-use, full-featured, cross-language, database-agnostic
programming model.



Q&A



Q Can I use ADO in the VBScript that runs under the browser?

A Yes, it's possible, but unless you use technology similar to that
covered in
actually within the same organization on the same local network.

Also, take into consideration that ADO is not currently marked as safe
for scri
to click the Accept button of a security warning dialog box. This
feature can b.

Q Can I create ActiveX Data Objects using HTML object tags?

A Yes, you can, but doing so falls under the same restrictions described
 in the
Class IDs are globally unique identifiers. No other class in existence,
 whether
they're also easy for independent developers to accidentally use for
completely.

Use this statement to create a recordset using HTML <object> tags:

<OBJECT NAME=rs CLSID="CLSID:00000281-0000-0010-8000-00AA006D2EA4">
</OBJECT>

To create a connection using HTML <object> tags, use this statement:

<OBJECT NAME=cn CLSID="CLSID:00000293-0000-0010-8000-00AA006D2EA4">
</OBJECT>

Here's how you create a command using HTML <object> tags:

<OBJECT NAME=cm CLSID="CLSID:0000022D-0000-0010-8000-00AA006D2EA4">
</OBJECT>

Q What editor should I use to build my Web pages?

A Use whatever editor is available that lets you insert HTML
instructions direc
design the initial pages, and then edit them separately under another
editor to.

Microsoft Visual InterDev lets you do both, but documenting Visual
InterDev is .

Q Where do I get ADO? How do I know if I already have it?

A If you have a complete installation of Internet Information Server 3.0
 or hig.

Another way to get ADO by itself is to install the OLE-DB Software
Development .

Q Do I have to buy Visual Basic to use Visual Basic Script in my Web
pages?

A No. Visual Basic Script is a subset of Visual Basic and is provided
with both.

Q Can I use JavaScript instead of Visual Basic Script when I add
customization ?

A Yes. Microsoft Internet Explorer 3.0 and Microsoft Internet
Information Serve
simple exercise would be to convert the examples from VBScript into
JavaScript.

Q Can scripting code running on the client call functions in scripting
code run?

A The server-side scripting code is executed only once and is the
means by whic
page is removed and generated HTML instructions are inserted in its
place (if a.

To call code running on the server from code running on the client,
investigate"

Q Can I access more than one database at a time?

A Yes. Multiple recordsets, commands, and connections can all be open
and funct
if you have one connection made to an Oracle database server, and
another, sepa
to a single server and by using product-specific features of that server
 to do .

Q Can I have more than one recordset open per connection?

A Yes, many recordsets may be open per connection. Likewise, many
commands may .

Q Can I use either DAO or RDO with Active Server Pages instead of ADO?

A Yes, but some restrictions may apply. Neither DAO nor RDO are
optimized for u
objects and are intended for use by only a single client-application
process at
lengthy runtimes and hundreds of thousands of repeated uses. This
level of reli.





Quiz



1. List all three main ADO objects.

2. What does the acronym ADO stand for?

3. What's the name of Visual Basic Script's built-in function that's
used to cr?

4. To do its work, the ADO recordset depends on what two other
objects?

5. Although the ADO Recordset object depends on other objects to do
its work, t?

6. The prefix ADODB, used when creating ADO objects, refers to what?

7. ADO can be used in which programming languages or environments?

8. ADO objects are, in fact, ActiveX objects. True or False?





Exercises



1. Show the Visual Basic statement needed to create an ADO Recordset
object.

2. Show the VBScript statement needed to create an ADO Recordset
object under t



<图片: TOC>

<图片>


〤opyright, Macmillan Computer Publishing. All rights reserved.



1. Show the Visual Basic statement needed to create an ADO Recordset
object.

2. Show the VBScript statement needed to create an ADO Recordset
object under t



--
为何在这里,无聊像半醉
曾在这空间,跟你相倾诉

※ 来源:.逸仙时空 Yat-sen Channel bbs.zsu.edu.cn.[FROM: 192.168.2.177]
--
※ 转寄:.逸仙时空 Yat-sen Channel bbs.zsu.edu.cn.[FROM: 210.39.3.50]
--
※ 转载:·BBS 荔园晨风站 bbs.szu.edu.cn·[FROM: 192.168.1.118]


[回到开始] [上一篇][下一篇]

荔园在线首页 友情链接:深圳大学 深大招生 荔园晨风BBS S-Term软件 网络书店