Directory listing of http: uap.unnes.ac.id ebook biblebook Visual Basic 6 com & Library Books

Visual Basic 6
Database
Programming Bible
®

Visual Basic 6
Database
Programming Bible
®

Wayne S. Freeze

IDG Bo o ks Wo rldwide, Inc .
An Internatio nal Data Gro up Co mpany
Fo ster City, CA ✦ Chic ago , IL ✦ Indianapo lis, IN ✦ New Yo rk, NY

Visual Basic ® 6 Database Programming Bible
Published by

IDG Books Worldwide, Inc.
An Internatio nal Data Gro up Co mpany

919 E. Hillsdale Blvd., Suite 400
Fo ster City, CA 94404
www.idgbooks.com (IDG Bo o ks Wo rldwide Web site)
Co pyright © 2000 IDG Bo o ks Wo rldwide, Inc . All
rights reserved. No part o f this bo o k, inc luding
interio r design, c o ver design, and ic o ns, may be
repro duc ed o r transmitted in any fo rm, by any means
(elec tro nic , pho to c o pying, rec o rding, o r o therwise)
witho ut the prio r written permissio n o f the publisher.
ISBN: 0-7645-4728-3
Printed in the United States o f Americ a
10 9 8 7 6 5 4 3 2 1
1O/ TR/ QY/ QQ/ FC
Distributed in the United States by IDG Bo o ks
Wo rldwide, Inc .
Distributed by CDG Bo o ks Canada Inc . fo r Canada;
by Transwo rld Publishers Limited in the United
Kingdo m; by IDG No rge Bo o ks fo r No rway; by IDG
Sweden Bo o ks fo r Sweden; by IDG Bo o ks Australia
Publishing Co rpo ratio n Pty. Ltd. fo r Australia and

New Zealand; by TransQuest Publishers Pte Ltd. fo r
Singapo re, Malaysia, Thailand, Indo nesia, and Ho ng
Ko ng; by Go to p Info rmatio n Inc . fo r Taiwan; by ICG
Muse, Inc . fo r Japan; by Interso ft fo r So uth Afric a;
by Eyro lles fo r Franc e; by Internatio nal Tho mso n
Publishing fo r Germany, Austria, and Switzerland;
by Distribuido ra Cuspide fo r Argentina; by LR
Internatio nal fo r Brazil; by Galileo Libro s fo r Chile;
by Edic io nes ZETA S.C.R. Ltda. fo r Peru; by WS
Co mputer Publishing Co rpo ratio n, Inc ., fo r the
Philippines; by Co ntempo ranea de Edic io nes fo r
Venezuela; by Express Co mputer Distributo rs fo r
the Caribbean and West Indies; by Mic ro nesia
Media Distributo r, Inc . fo r Mic ro nesia; by Chips
Co mputado ras S.A. de C.V. fo r Mexic o ; by Edito rial
No rma de Panama S.A. fo r Panama; by Americ an
Bo o ksho ps fo r Finland.

Fo r general info rmatio n o n IDG Bo o ks Wo rldwide’s
bo o ks in the U.S., please c all o ur Co nsumer Custo mer

Servic e department at 800-762-2974. Fo r reseller
info rmatio n, inc luding disc o unts and premium sales,
please c all o ur Reseller Custo mer Servic e
department at 800-434-3422.
Fo r info rmatio n o n where to purc hase IDG Bo o ks
Wo rldwide’s bo o ks o utside the U.S., please c o ntac t
o ur Internatio nal Sales department at 317-596-5530
o r fax 317-572-4002.
Fo r c o nsumer info rmatio n o n fo reign language
translatio ns, please c o ntac t o ur Custo mer Servic e
department at 800-434-3422, fax 317-572-4002, o r
e-mail rights@idgbo o ks.c o m.
Fo r info rmatio n o n lic ensing fo reign o r do mestic
rights, please pho ne +1-650-653-7098.
Fo r sales inquiries and spec ial pric es fo r bulk quantities, please c o ntac t o ur Order Servic es department
at 800-434-3422 o r write to the address abo ve.
Fo r info rmatio n o n using IDG Bo o ks Wo rldwide’s
bo o ks in the c lassro o m o r fo r o rdering examinatio n
c o pies, please c o ntac t o ur Educ atio nal Sales
department at 800-434-2086 o r fax 317-572-4005.

Fo r press review c o pies, autho r interviews, o r o ther
public ity info rmatio n, please c o ntac t o ur Public
Relatio ns department at 650-653-7000 o r fax
650-653-7500.
Fo r autho rizatio n to pho to c o py items fo r c o rpo rate,
perso nal, o r educ atio nal use, please c o ntac t
Co pyright Clearanc e Center, 222 Ro sewo o d Drive,
Danvers, MA 01923, o r fax 978-750-4470.

Library of Congress Cataloging-in-Publication Data
Freeze, Wayne S.
Visual Basic 6 Database pro gramming bible /
Wayne S. Freeze.
p. c m.
ISBN 0-7645-4728-3 (alk. paper)
1. Web databases. 2. Client/ server c o mputing.
3. Mic ro so ft Visual BASIC. I. Title.
QA76.9.W43 f74 2000
005.75'8 --dc 21
00-058197


LIMIT OF LIABILITY/ DISCLAIMER OF WARRANTY: THE PUBLISHER AND AUTHOR HAVE USED THEIR
BEST EFFORTS IN PREPARING THIS BOOK. THE PUBLISHER AND AUTHOR MAKE NO
REPRESENTATIONS OR WARRANTIES WITH RESPECT TO THE ACCURACY OR COMPLETENESS OF THE
CONTENTS OF THIS BOOK AND SPECIFICALLY DISCLAIM ANY IMPLIED WARRANTIES OF
MERCHANTABILITY OR FITNESS FOR A PARTICULAR PURPOSE. THERE ARE NO WARRANTIES WHICH
EXTEND BEYOND THE DESCRIPTIONS CONTAINED IN THIS PARAGRAPH. NO WARRANTY MAY BE
CREATED OR EXTENDED BY SALES REPRESENTATIVES OR WRITTEN SALES MATERIALS. THE
ACCURACY AND COMPLETENESS OF THE INFORMATION PROVIDED HEREIN AND THE OPINIONS
STATED HEREIN ARE NOT GUARANTEED OR WARRANTED TO PRODUCE ANY PARTICULAR RESULTS,
AND THE ADVICE AND STRATEGIES CONTAINED HEREIN MAY NOT BE SUITABLE FOR EVERY
INDIVIDUAL. NEITHER THE PUBLISHER NOR AUTHOR SHALL BE LIABLE FOR ANY LOSS OF PROFIT OR
ANY OTHER COMMERCIAL DAMAGES, INCLUDING BUT NOT LIMITED TO SPECIAL, INCIDENTAL,
CONSEQUENTIAL, OR OTHER DAMAGES.
Trademarks: All brand names and pro duc t names used in this bo o k are trade names, servic e marks,
trademarks, o r registered trademarks o f their respec tive o wners. IDG Bo o ks Wo rldwide is no t asso c iated
with any pro duc t o r vendo r mentio ned in this bo o k.
is a registered trademark under exc lusive
lic ense to IDG Bo o ks Wo rldwide, Inc .,
fro m Internatio nal Data Gro up, Inc .


Welcome to the world of IDG Books Worldwide.
IDG Books Worldwide, Inc., is a subsidiary of International Data Group, the world’s largest publisher of
computer-related information and the leading global provider of information services on information technology.
IDG was founded more than 30 years ago by Patrick J. McGovern and now employs more than 9,000 people
worldwide. IDG publishes more than 290 computer publications in over 75 countries. More than 90 million
people read one or more IDG publications each month.
Launched in 1990, IDG Books Worldwide is today the #1 publisher of best-selling computer books in the
United States. We are proud to have received eight awards from the Computer Press Association in recognition
of editorial excellence and three from Computer Currents’ First Annual Readers’ Choice Awards. Our bestselling ...For Dummies® series has more than 50 million copies in print with translations in 31 languages. IDG
Books Worldwide, through a joint venture with IDG’s Hi-Tech Beijing, became the first U.S. publisher to
publish a computer book in the People’s Republic of China. In record time, IDG Books Worldwide has become
the first choice for millions of readers around the world who want to learn how to better manage their
businesses.
Our mission is simple: Every one of our books is designed to bring extra value and skill-building instructions
to the reader. Our books are written by experts who understand and care about our readers. The knowledge
base of our editorial staff comes from years of experience in publishing, education, and journalism —
experience we use to produce books to carry us into the new millennium. In short, we care about books, so
we attract the best people. We devote special attention to details such as audience, interior design, use of
icons, and illustrations. And because we use an efficient process of authoring, editing, and desktop publishing

our books electronically, we can spend more time ensuring superior content and less time on the technicalities
of making books.
You can count on our commitment to deliver high-quality books at competitive prices on topics you want
to read about. At IDG Books Worldwide, we continue in the IDG tradition of delivering quality for more than
30 years. You’ll find no better book on a subject than one from IDG Books Worldwide.

John Kilcullen
Chairman and CEO
IDG Books Worldwide, Inc.

Eighth Annual
Computer Press
Awards
1992

Ninth Annual
Computer Press
Awards
1993


Tenth Annual
Computer Press
Awards
1994

Eleventh Annual
Computer Press
Awards
1995

IDG is the world’s leading IT media, research and exposition company. Founded in 1964, IDG had 1997 revenues of $2.05
billion and has more than 9,000 employees worldwide. IDG offers the widest range of media options that reach IT buyers
in 75 countries representing 95% of worldwide IT spending. IDG’s diverse product and services portfolio spans six key areas
including print publishing, online publishing, expositions and conferences, market research, education and training, and
global marketing services. More than 90 million people read one or more of IDG’s 290 magazines and newspapers, including
IDG’s leading global brands — Computerworld, PC World, Network World, Macworld and the Channel World family of
publications. IDG Books Worldwide is one of the fastest-growing computer book publishers in the world, with more than
700 titles in 36 languages. The “...For Dummies® ” series alone has more than 50 million copies in print. IDG offers online
users the largest network of technology-specific Web sites around the world through IDG.net (http://www.idg.net), which
comprises more than 225 targeted Web sites in 55 countries worldwide. International Data Corporation (IDC) is the world’s

largest provider of information technology data, analysis and consulting, with research centers in over 41 countries and more
than 400 research analysts worldwide. IDG World Expo is a leading producer of more than 168 globally branded conferences
and expositions in 35 countries including E3 (Electronic Entertainment Expo), Macworld Expo, ComNet, Windows World
Expo, ICE (Internet Commerce Expo), Agenda, DEMO, and Spotlight. IDG’s training subsidiary, ExecuTrain, is the world’s
largest computer training company, with more than 230 locations worldwide and 785 training courses. IDG Marketing
Services helps industry-leading IT companies build international brand recognition by developing global integrated marketing
programs via IDG’s print, online and exposition products worldwide. Further information about the company can be found
at www.idg.com.
1/26/00

Credits
Acquisitions Editor

Quality Control Technician

Greg Cro y

Dina F Quan

Project Editors


Media Development Specialist

Brian Mac Do nald
Valerie Perry

Travis Silvers

Permissions Editor
Technical Editor

Jessic a Mo ntgo mery

Allen Wyatt

Media Development Coordinator
Copy Editors

Marisa Pearman


Gabrielle Cho sney
Kevin Kent

Permissions Editor
Jessic a Mo ntgo mery

Proof Editor
Neil Ro mano sky

Media Development Manager
Stephen No etzel

Project Coordinators
Danette Nurse
Lo uigene A. Santo s

Proofreading and Indexing

Graphics and Production Specialist

Cover Illustration

Bo o klayers.c o m

Jo anne Vuo ng

Yo rk Pro duc tio n Servic es

About the Author
Wayne S. Freeze is a full-time autho r and c o mputer tec hno lo gy c o nsultant. He has
written nine different bo o ks o n Visual Basic and SQL Server sinc e he began his
c areer three years ago .
He lives in Beltsville, Maryland, with his lo vely wife, Jill, and their wo nderful c hildren, Christo pher, age six, and Samantha, age five. Jill is a well-respec ted writer
and Mic ro so ft beta tester, spec ializing in Mic ro so ft Offic e, Internet Explo rer, and
Windo ws. Chris is perhaps the yo ungest perso n to beta test so ftware fo r Mic ro so ft,
having tested bo th Windo ws 98 and Mic ro so ft Millennium, amo ng o ther pro duc ts,
in his sho rt c areer. Sam, o n the o ther hand, lo ves to sit o n Wayne’s lap, and o ne
day ho pes to write bo o ks just like her mo m and dad.
To gether, they live in a ho use full o f animals, inc luding a go lden retriever named
Lady Ko ko mo and fo ur c ats named Pixel, Terry, Cali, and Dusty. Wayne also has a
pet stingray named Raymo nd, after his father-in-law. Raymo nd lo ves to eat wo rms
fro m Wayne’s hand (the stingray, that is, no t his father-in-law).
Wayne maintains a Web site at www.JustPC.com that c o ntains info rmatio n abo ut
the vario us bo o ks he and his wife have written. Please take the time to visit their
Web site and sign their guest bo o k.

This bo o k is de dicate d to the ne we st me mbe r o f my family, Dusty.

Preface

W

ith respec t to the develo pment o f database applic atio ns, Visual Basic is the
language o f c ho ic e fo r pro grammers all o ver the wo rld. There are many reaso ns they c ho o se Visual Basic : o ne, it is easy to learn ho w to use; two , yo u c an build
c o mplex applic atio ns faster in Visual Basic than in any o ther pro gramming language;
and three, Visual Basic pro grams are easy to debug. In additio n, there is a lo t o f spec ialized suppo rt built into Visual Basic fo r develo ping database applic atio ns. No t o nly
c an yo u develo p traditio nal, fo rms-o riented database applic atio ns using Visual Basic ,
yo u c an also use it to develo p bac kend database pro grams fo r yo ur Web server that
are far mo re effic ient than traditio nal PERL sc ripts o r Ac tive Server Pages.
Mo st o f the Visual Basic bo o ks o n the market to day, ho wever, do wnplay these
database aspec ts in favo r o f all o f the o ther neat features built into the language.
While c alling API func tio ns fro m Visual Basic and develo ping Add-ins fo r the IDE c an
be useful to pic s, I c o ver far mo re database-o riented material than yo u wo uld find in
a typic al Visual Basic pro gramming bo o k by fo c using stric tly o n database pro gramming aspec ts. Yo u’ll benefit fro m the mo re fo c used c o verage, bec ause yo u’ll learn
abo ut the database features that yo u need to kno w and whic h will make yo u a mo re
pro duc tive database pro grammer.

Who Should Read This Book
If yo u read the bac k c o ver, yo u’ll find that this bo o k is aimed at beginning to
advanc ed readers. That’s quite a c hallenge. I do n’t want to bo re advanc ed pro grammers, who may want to learn tho se dirty tric ks that wo uld make their applic atio ns
mo re effic ient, yet I do n’t want to lo se no vic e database pro grammers who c o uld
benefit fro m tho se same tric ks.
I’m go ing to assume that everyo ne reading this bo o k is familiar with ho w to c reate
and debug a Visual Basic pro gram — no t just the simple “Hello Wo rld” variety, but
o ne that had so muc h c o de, fo r instanc e, it didn’t wo rk the first time yo u tried to
c o mpile and run it. I’ll intro duc e yo u to any o ther info rmatio n yo u’ll need beyo nd
this level.
Advanc ed readers may benefit fro mso me o f the mo re intro duc to ry material,
bec ause I o ften use no ntraditio nal ways o f do ing things. (I’m kno wn as The Lazy
Pro grammer, bec ause I try to take advantage o f every sho rtc ut available to me, as
lo ng as it saves me wo rk in the lo ng run.) After this initial review, advanc ed readers
c an then dig into why they sho uld be using bo th the COM+ Transac tio n Server and
the Mic ro so ft Message Queues with their IIS Applic atio n-based applic atio n.

x

Visual Basic 6 Database Programming Bible

What This Book Covers
This bo o k is designed to be the o nly c o mbinatio n referenc e and tuto rial yo u will
need fo r building Visual Basic database applic atio ns. To ac c o mplish that, this bo o k
c o vers the fo llo wing database systems:

✦ Mic ro so ft SQL Server 7
✦ Mic ro so ft Jet 3.51/ 4.0
✦ Orac le 8i
Bec ause muc h o f the material yo u need to kno w abo ut database pro gramming is
c o mmo n to all three database servers, I have presented it first, in the fo llo wing list
o f to pic s:

✦ Database Pro gramming Fundamentals
✦ Ac tiveX Data Objec ts (ADO)
✦ Ac tiveX Data Objec t Extensio ns (ADOX)
✦ Traditio nal c lient/ server applic atio ns
✦ IIS Applic atio ns
✦ Bo und c o ntro ls
✦ Sto red pro c edures
✦ COM+ Transac tio n Server
✦ Mic ro so ft Message Queues
✦ XML
Onc e I finish c o vering the c o mmo n material, I’ll fo c us o n eac h individual database
server to give yo u the spec ific kno wledge yo u need to build effic ient database applic atio ns. Fo r eac h o f the database servers, I’ll c o ver these to pic s:

✦ Database server to o ls and utilities
✦ Useful SQL language extensio ns
✦ ADO c o nsideratio ns
✦ Unique data types and their Visual Basic equivalents
✦ Sec urity mec hanisms
✦ Creating sto red pro c edures
✦ Perfo rmanc e c o nsideratio ns

Preface

The ac c o mpanying CD-ROM c o ntains all o f the sample pro grams fo und in this bo o k,
plus a sample database that yo u c an use to test these pro grams. It’s my belief that
the best way to learn pro gramming is to study as many pro grams as po ssible. Sinc e
the c o mplete sample pro grams are o n disk, yo u c an lo ad them, try them o ut, and
mo dify them to see ho w they wo rk, and ho pefully inc o rpo rate the same tec hniques
into yo ur o wn applic atio ns.

What This Book Doesn’t Cover
This bo o k will no t teac h yo u the fundamentals o f Visual Basic pro gramming. If yo u
do n’t kno w what a For Next lo o p o r a Function is, run to the nearest bo o ksto re
and get a c o py o f Visual Basic 6 fo r Dummie s by Wallac e Wang. When yo u finish that
bo o k and understand the material in it, yo u’ll be ready fo r this bo o k.
While this b o o k inc ludes a primer o n relatio nal datab ase c o nc epts and the SQL
language, I suggest that yo u read SQL fo r Dummie s b y Allen G. Taylo r fo r a mo re
in-depth c o verage o f SQL and relatio nal datab ases. Yo u may also want to c hec k
o ut Micro so ft SQL Se rve r 7 fo r Dummie s b y Antho ny T. Mann and Oracle 8i fo r
Dummie s b y Caro l Mc Cullo ugh fo r mo re info rmatio n ab o ut the spec ific datab ase
servers c o vered in this b o o k.
Ano ther thing to c o nsider is that the emphasis in this bo o k is o n database pro gramming. While this is a fairly bro ad to pic , there are many things yo u might want to
inc lude in yo ur pro grams that I might no t c o ver, suc h as ho w to c o nstruc t help files,
ho w to use reso urc e files to so lve lo c alizatio n issues, and ho w to send e-mail messages using MAPI. Yo u might c hec k o ut the Visual Basic 6 Bible by Eric A. Smith,
Valo r Whisler, and Hank Marquis, o r so me o f my o ther Visual Basic bo o ks. Yo u c an
find a c o mplete list o f bo o ks that I have written at www.JustPC.com.

Hardware and Software Requirements
I wro te this bo o k using two c o mputers: o ne (c alled Myc ro ft) fo r running Visual
Basic , and ano ther (kno wn as Athena) to run my database servers plus the COM+
Transac tio n Server. Myc ro ft is a Gateway 9100 lapto p with a Pentium 200 pro c esso r
and 64MB o f main memo ry, alo ng with Windo ws 98 Sec o nd Editio n, Visual Basic 6
Enterprise Editio n, Offic e 2000, and the SQL Server 7 utilities. I also installed ADO
versio n 2.5 o n my develo pment mac hine fro m the Platfo rm SDK. Yo u c an do wnlo ad
the parts o f the Platfo rm SDK fro m http://msdn.Microsoft.com. Just go to the
Do wnlo ads sec tio n and fo llo w the direc tio ns to do wnlo ad the Platfo rm SDK installatio n pro gram.

xi

xii

Visual Basic 6 Database Programming Bible

The database server is also Gateway c o mputer with a Pentium 120 pro c esso r and
80MB o f main memo ry, running Windo ws 2000 Server. Obvio usly, SQL Server 7 and
Orac le 8i were installed, plus the Internet Info rmatio n Server (IIS), Mic ro so ft Message
Queues, and COM+ Transac tio n Server. Just fo r fun, I also installed Offic e 2000 and
Visual Basic 6 o n this mac hine. The two c o mputers were c o nnec ted using a 10 MHz
Ethernet LAN. The c o mbinatio n was a lo t slo wer than I wo uld have liked, even after I
spent a lo t o f time retuning the system fo r o ptimal perfo rmanc e.
Running a database server isn’t a trivial task, espec ially if yo u want to run it o n
Windo ws 2000 Server. Windo ws 2000 needs a lo t o f memo ry in o rder to have an
ac c eptable level o f perfo rmanc e. I rec o mmend a minimum o f 256MB o f memo ry fo r
Windo ws 2000 Server, tho ugh yo u c o uld get by with 128MB o f memo ry if yo u wanted
to run Windo ws NT 4 Server. If po ssible, yo u sho uld have a minimum o f a 400MHz
Pentium pro c esso r, tho ugh yo u c o uld get by with less if yo ur server isn’t heavily
lo aded.
While it’s po ssible to run yo ur database and Visual Basic o n o ne mac hine, yo u’ll be
happier if yo u c an dedic ate o ne mac hine to SQL Server and use a sec o nd fo r yo ur
pro gramming. If yo u do c ho o se to use a single mac hine, yo u sho uld have a lo t o f
memo ry, espec ially if yo u are running Windo ws 2000 server. Yo u sho uld also try to
invest in a dual pro c esso r system with relatively fast SCSI disk drives.

Visit M y Web Site
I maintain a Web site at http://www.JustPC.com with additio nal info rmatio n
abo ut the bo o ks that my wife and I have written. Eac h bo o k has its o wn Web page,
o n whic h I answer frequently asked questio ns and po int yo u to o ther reso urc es yo u
may find interesting. If yo u get a c hanc e to sto p by, please sign my guest bo o k to let
me kno w yo u were there.
Yo u’re also welc o me to send me e-mail at WFreeze@JustPC.com. Let me kno w what
yo u liked abo ut the bo o k and what yo u didn’t. I’ve made friends with readers fro m
all o ver the wo rld by do ing this. Ho wever, please understand that I make my living
fro m writing, so asking me to be yo ur unpaid c o nsultant isn’t fair to yo u o r me. I
kno w what it is like to have a c ritic al pro jec t and no t be able to get the answers I
need in a hurry. If I c an help, I will. Ho wever, my prio rities are my family, my c urrent
bo o k (tho ugh my edito rs may think it sho uld have a higher prio rity), my readers,
my Web site, and then everyo ne else. So do n’t be surprised if yo u send me a no te,
and a few weeks (o r even mo nths) later yo u hear fro m me. Writing a bo o k suc h as
this o ne takes a c o nsiderable amo unt o f time, and many things, like sleeping, eating
so mewhere o ther than my desk, and answering e-mail, are o ften put o ff until after
the bo o k is finished.

Preface

No w do n’t be afraid to send me e-mail. I enjo y reading every no te I get and I do read
every single no te. I’ve always enjo yed teac hing peo ple ho w to do things, and writing a bo o k allo ws me to teac h mo re peo ple than I’ve ever had the o ppo rtunity to do
befo re. Unfo rtunately, I miss the feedbac k that yo u get fro m teac hing so meo ne in
perso n. E-mail is my link to yo u. So while I c an’t meet everyo ne in perso n, hearing
fro m yo u via e-mail is the next best thing.

xiii

Acknowledgments

S

o metimes, being a writer c an be the pits. The ho urs are lo ng, the edito rs are
demanding, and yo u never seem to have time fo r yo ur family and friends.
Everyo ne believes that yo u wo rk a few ho urs eac h mo rning if yo u feel like it, and then
have the rest o f the day to play. What a laugh! As I write this, my c hildren have been
asleep fo r abo ut eight ho urs, and they’ll be getting up sho rtly to leave fo r sc ho o l. My
wife has been asleep fo r a few ho urs no w, and the o nly o ne awake, beside myself, is
my c at Pixel, who has walked ac ro ss my keybo ard three times while I’ve tried to write
this paragraph. I wish she wo uld go to sleep, to o . On the o ther hand, writing is so metimes its o wn reward. I enjo y so lving pro blems and teac hing o thers ho w to do things.
Writing allo ws me to do bo th, witho ut the day-to -day headac hes that arise as a manager in a large c o mputer c enter.
So while the rest o f the wo rld believes that writing is o nly a part-time jo b, I’d like to
ac kno wledge a few o ther peo ple who believe o therwise.
My agent, Laura Belt, really earns her c o mmissio ns. She do es her best to ensure
that I have mo ney fo r the things that mo st writers do n’t have, like elec tric ity to run
my c o mputer and a ro o f o ver my head. No w if I c o uld o nly affo rd so mething to eat.
My ac quisitio ns edito r, Jo hn Osbo rn, c hallenged me to do this pro jec t with an
impo ssibly tight sc hedule, and in a weak mo ment, I agreed. Ho wever, befo re I had a
c hanc e to really get started o n this bo o k, he left fo r greener pastures. I’m no w wo rking with Greg Cro y, who has been keeping me bo th c hallenged and busy.
Shaun, Elwyn, Ric k, Ariane, Dr. Bo b, Vero nic a, Sc o tt, Randy, Vikki, Bo b K., and Ian,
are but a few o f my friends that I haven’t seen in mo nths. I pro mise to c all real so o n.
Really. Okay, maybe after I finish the next bo o k. That is, exc ept fo r Ric k. I may need
to sto p by and pic k yo ur brain and yo ur c lo set.
Buc ky and Go o se, my wife’s parents. I do n’t think I c o uld ask fo r a better set o f inlaws. See y’all in a c o uple o f days fo r the big party.
I want to thank my mo m and dad fo r their suppo rt, even tho ugh they think I need a
hairc ut. It seems like I never get to see my mo ther and father as o ften as I wish. I
ho pe that c hanges in the future, sinc e they are bo th very spec ial peo ple to me.

xvi

Visual Basic 6 Database Programming Bible

If yo u read this bo o k c arefully, yo u will find o c c asio nal referenc es to Christo pher,
Samantha, and Jill. Chris, who is six, kno ws mo re abo ut c o mputers than so me wellpaid peo ple I used to wo rk with and has beta tested mo re so ftware o n his c o mputer
than mo st adults I kno w. While Samantha is o nly five, she already wants her o wn
lapto p c o mputer so she c an write bo o ks like her mo mmy and daddy.
My lo vely wife, Jill, is a very respec ted writer and b eta tester in her o wn right,
having written b o o ks o n Mic ro so ft Offic e, Internet Explo rer, and Windo ws. Jill, if
yo u b elieve in yo urself, anything is po ssib le! I lo ve yo u!

Contents at a Glance
Prefac e . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . ix
Ac kno wledgments . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . xv

Part I: Database Programming Fundamentals . . . . . . . . . . . . . . . 1
Chapter 1: Basic Co nc epts . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 3
Chapter 2: The Relatio nal Database Mo del . . . . . . . . . . . . . . . . . . . . . . 19
Chapter 3: Designing a Relatio nal Database . . . . . . . . . . . . . . . . . . . . . . 31
Chapter 4: SQL Statement Primer . . . . . . . . . . . . . . . . . . . . . . . . . . . . 49
Chapter 5: Intro duc ing Visual Basic . . . . . . . . . . . . . . . . . . . . . . . . . . 77
Chapter 6: Ac c essing Databases fro m Visual Basic . . . . . . . . . . . . . . . . . . 89

Part II: Beginning Database Programming . . . . . . . . . . . . . . . 103
Chapter 7: Co deless Database Pro gramming . . . . . . . . . . . . . . . .
Chapter 8: Mo re Abo ut Bo und Co ntro ls . . . . . . . . . . . . . . . . . .
Chapter 9: Pro gramming with Data Enviro nments . . . . . . . . . . . .
Chapter 10: Building Repo rts with the Mic ro so ft Data Repo rt Designer

.
.
.
.

.
.
.
.

.
.
.
.

.
.
.
.

.
.
.
.

105
119
141
169

Part III: Hardcore ADO . . . . . . . . . . . . . . . . . . . . . . . . . . . 199
Chapter 11: The ADO Objec t Mo del . . . . . . . . . . .
Chapter 12: Co nnec ting to a database . . . . . . . . .
Chapter 13: Using Co mmands and Sto red Pro c edures
Chapter 14: Wo rking with Rec o rdsets — Part I . . . . .
Chapter 15: Wo rking with Rec o rdsets — Part II . . . .
Wo rking with Rec o rdsets — Part III . . . . . . . . . . .

.
.
.
.
.
.

.
.
.
.
.
.

.
.
.
.
.
.

.
.
.
.
.
.

.
.
.
.
.
.

.
.
.
.
.
.

.
.
.
.
.
.

.
.
.
.
.
.

.
.
.
.
.
.

.
.
.
.
.
.

.
.
.
.
.
.

.
.
.
.
.
.

.
.
.
.
.
.

.
.
.
.
.
.

.
.
.
.
.
.

201
211
235
265
299
327

Part IV: COM + Transactions and M essage Queues . . . . . . . . . . 347
Chapter 17: Building Yo ur Own Bo und Co ntro ls . . . . . . . . . . . . . . . . . . . 349
Chapter 18: Using COM+ Transac tio ns . . . . . . . . . . . . . . . . . . . . . . . . 369
Chapter 19: Using Message Queues . . . . . . . . . . . . . . . . . . . . . . . . . . 399

Part V: The Impact of XM L . . . . . . . . . . . . . . . . . . . . . . . . . 431
Chapter 20: Intro duc ing XML . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 433
Chapter 21: The Do c ument Objec t Mo del . . . . . . . . . . . . . . . . . . . . . . 455
Chapter 22: Integrating XML with Internet Info rmatio n Server Applic atio ns . . 483

xviii

Visual Basic 6 Database Programming Bible

Part VI: SQL Server . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 505
Chapter 23: Overview o f SQL Server . . . . . . . . . . . . . . . . . . . . . . . . . 507
Chapter 24: Creating Database Objec ts with SQL Server . . . . . . . . . . . . . . 523
Chapter 25: Creating Sto red Pro c edures with SQL Server . . . . . . . . . . . . . 557

Part VII: Oracle 8i . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 579
Chapter 26: Overview o f Orac le8i . . . . . . . . . . . . . . . . . . . . . . . . . . . 581
Chapter 27: Creating Database Objec ts with Orac le8i . . . . . . . . . . . . . . . 599
Chapter 28: Creating Sto red Pro c edures with Orac le8i . . . . . . . . . . . . . . . 627

Part VIII: M icrosoft Jet . . . . . . . . . . . . . . . . . . . . . . . . . . . 647
Chapter 29: Overview o f Mic ro so ft Jet . . . . . . . . . . . . . . . . . . . . . . . . 649
Chapter 30: Creating Database Objec ts with Mic ro so ft Jet . . . . . . . . . . . . . 663
Appendix: CD-ROM Installatio n Instruc tio ns . . . . . . . . . . . . . . . . . . . . . 679
Index . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 709
End Users Lic ense . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 729
CD-ROM Installatio n Instruc tio ns . . . . . . . . . . . . . . . . . . . . . . . . . . . 733

Contents
Preface. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . ix
Acknow ledgm ents . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . xv

Part I: Database Programming Fundamentals

1

Chapter 1: Basic Concepts . . . . . . . . . . . . . . . . . . . . . . . . . . 3
Why Use a Database? . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 3
Sto ring info rmatio n . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 3
Co nc urrenc y . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 5
Sec uring yo ur data . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 6
Perfo rming bac kups and using transac tio n lo gs . . . . . . . . . . . . . 6
A database is the answer . . . . . . . . . . . . . . . . . . . . . . . . . . . 7
Database Arc hitec ture . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 8
Servers and c lients . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 8
Database servers and database c lients . . . . . . . . . . . . . . . . . . 9
Types o f Databases . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 11
Hierarc hic al databases . . . . . . . . . . . . . . . . . . . . . . . . . . . 11
Netwo rked databases . . . . . . . . . . . . . . . . . . . . . . . . . . . . 11
Indexed databases . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 13
Relatio nal databases . . . . . . . . . . . . . . . . . . . . . . . . . . . . 13
Co mmo n Databases . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 14
SQL Server 7.0 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 14
Mic ro so ft Jet 3.5/ 4.0 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 15
Orac le 8i . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 15

Chapter 2: The Relational Database M odel . . . . . . . . . . . . . . . 19
Intro duc ing the Struc tured Query Language . .
Relatio nal histo ry . . . . . . . . . . . . . .
Business benefits o f a relatio nal database
Parts o f a Relatio nal Database . . . . . . . . . .
Tables and ro ws o f data . . . . . . . . . . .
Co lumns and data types . . . . . . . . . .
Indexes and keys . . . . . . . . . . . . . . .
Views . . . . . . . . . . . . . . . . . . . . .
No rmalizatio n . . . . . . . . . . . . . . . . . . . .

.
.
.
.
.
.
.
.
.

.
.
.
.
.
.
.
.
.

.
.
.
.
.
.
.
.
.

.
.
.
.
.
.
.
.
.

.
.
.
.
.
.
.
.
.

.
.
.
.
.
.
.
.
.

.
.
.
.
.
.
.
.
.

.
.
.
.
.
.
.
.
.

.
.
.
.
.
.
.
.
.

.
.
.
.
.
.
.
.
.

.
.
.
.
.
.
.
.
.

.
.
.
.
.
.
.
.
.

.
.
.
.
.
.
.
.
.

.
.
.
.
.
.
.
.
.

.
.
.
.
.
.
.
.
.

.
.
.
.
.
.
.
.
.

19
19
23
24
24
24
25
27
27

xx

Visual Basic 6 Database Programming Bible

Chapter 3: Designing a Relational Database . . . . . . . . . . . . . . . 31
Overview o f the Design Pro c ess . . . .
Stating the Pro blem . . . . . . . . . . .
Brainsto rming . . . . . . . . . . . . . .
Brainsto rming To y Co llec to r . . .
Reviewing the results . . . . . . .
Mapping the results to data types
Mo deling Entities and Relatio nships . .
Entity/ relatio nship mo deling . . .
Identifying entities and attributes
Identifying Relatio nships . . . . .
Drawing the E/ R mo del . . . . . .
Building the Database . . . . . . . . . .

.
.
.
.
.
.
.
.
.
.
.
.

.
.
.
.
.
.
.
.
.
.
.
.

.
.
.
.
.
.
.
.
.
.
.
.

.
.
.
.
.
.
.
.
.
.
.
.

.
.
.
.
.
.
.
.
.
.
.
.

.
.
.
.
.
.
.
.
.
.
.
.

.
.
.
.
.
.
.
.
.
.
.
.

.
.
.
.
.
.
.
.
.
.
.
.

.
.
.
.
.
.
.
.
.
.
.
.

.
.
.
.
.
.
.
.
.
.
.
.

.
.
.
.
.
.
.
.
.
.
.
.

.
.
.
.
.
.
.
.
.
.
.
.

.
.
.
.
.
.
.
.
.
.
.
.

.
.
.
.
.
.
.
.
.
.
.
.

.
.
.
.
.
.
.
.
.
.
.
.

.
.
.
.
.
.
.
.
.
.
.
.

.
.
.
.
.
.
.
.
.
.
.
.

.
.
.
.
.
.
.
.
.
.
.
.

.
.
.
.
.
.
.
.
.
.
.
.

.
.
.
.
.
.
.
.
.
.
.
.

.
.
.
.
.
.
.
.
.
.
.
.

31
32
33
33
34
36
37
37
38
44
45
46

Chapter 4: SQL Statement Primer . . . . . . . . . . . . . . . . . . . . . 49
Using SQL Statements . . . . . . . . . .
SQL statements . . . . . . . . . .
SQL data types . . . . . . . . . . .
Testing SQL statements . . . . . .
The Selec t statement . . . . . . . . . .
Simple Selec t statements . . . . .
Selec ting a subset o f a table . . .
So rting results . . . . . . . . . . .
Using multiple tables . . . . . . .
Nested queries . . . . . . . . . . .
Using func tio ns . . . . . . . . . .
Inserting Ro ws into a Table . . . . . . .
A simple Insert statement . . . .
Deleting Ro ws fro m a Table . . . . . . .
A Sample Delete Statement . . . .
Updating Ro ws in a Table . . . . . . . .
A Sample Update Statement . . .
The Create Table Statement . . . . . . .
The Create Index Statement . . . . . .
A Sample Create Index Statement
The Create View Statement . . . . . . .

.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.

.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.

.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.

.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.

.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.

.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.

.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.

.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.

.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.

.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.

.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.

.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.

.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.

.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.

.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.

.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.

.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.

.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.

.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.

.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.

.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.

49
49
50
53
53
54
56
59
60
62
63
64
65
67
67
68
69
70
71
72
72

Chapter 5: Introducing Visual Basic . . . . . . . . . . . . . . . . . . . . 77
Why Use Visual Basic ? . . .
Basic histo ry . . . . .
Database integratio n
Visual Basic Editio ns . . . .
Learning Editio n . . .
Pro fessio nal Editio n .
Enterprise Editio n . .
Other Variatio ns . . .

.
.
.
.
.
.
.
.

.
.
.
.
.
.
.
.

.
.
.
.
.
.
.
.

.
.
.
.
.
.
.
.

.
.
.
.
.
.
.
.

.
.
.
.
.
.
.
.

.
.
.
.
.
.
.
.

.
.
.
.
.
.
.
.

.
.
.
.
.
.
.
.

.
.
.
.
.
.
.
.

.
.
.
.
.
.
.
.

.
.
.
.
.
.
.
.

.
.
.
.
.
.
.
.

.
.
.
.
.
.
.
.

.
.
.
.
.
.
.
.

.
.
.
.
.
.
.
.

.
.
.
.
.
.
.
.

.
.
.
.
.
.
.
.

.
.
.
.
.
.
.
.

.
.
.
.
.
.
.
.

.
.
.
.
.
.
.
.

.
.
.
.
.
.
.
.

.
.
.
.
.
.
.
.

.
.
.
.
.
.
.
.

.
.
.
.
.
.
.
.

.
.
.
.
.
.
.
.

.
.
.
.
.
.
.
.

.
.
.
.
.
.
.
.

77
77
80
82
83
83
84
84

Contents

Types o f Visual Basic Pro grams .
Standard EXEs . . . . . . . .
Ac tiveX DLLs/ Co ntro ls/ EXEs
IIS Applic atio ns . . . . . . .
DHTML Applic atio ns . . . .

.
.
.
.
.

.
.
.
.
.

.
.
.
.
.

.
.
.
.
.

.
.
.
.
.

.
.
.
.
.

.
.
.
.
.

.
.
.
.
.

.
.
.
.
.

.
.
.
.
.

.
.
.
.
.

.
.
.
.
.

.
.
.
.
.

.
.
.
.
.

.
.
.
.
.

.
.
.
.
.

.
.
.
.
.

.
.
.
.
.

.
.
.
.
.

.
.
.
.
.

.
.
.
.
.

.
.
.
.
.

.
.
.
.
.

.
.
.
.
.

85
85
86
87
87

Chapter 6: Accessing Databases from Visual Basic . . . . . . . . . . . 89
Mic ro so ft Database Pro gramming APIs . . . . . . . . . . . . . . . . . . . . . 89
ODBC . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 90
ODBC arc hitec ture . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 90
Drawbac ks to ODBC . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 91
Database Ac c ess Objec ts (DAO) . . . . . . . . . . . . . . . . . . . . . . 91
Remo te Database Objec ts (RDO) . . . . . . . . . . . . . . . . . . . . . 92
OLE DB . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 92
Data pro viders . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 92
Data c o nsumers . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 93
Ac tiveX Data Objec ts (ADO) . . . . . . . . . . . . . . . . . . . . . . . . 93
OLE DB pro viders . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 93
Custo m OLE DB pro viders . . . . . . . . . . . . . . . . . . . . . . . . . 94
Visual Basic Database To o ls . . . . . . . . . . . . . . . . . . . . . . . . . . . 94
Data Enviro nment Designer . . . . . . . . . . . . . . . . . . . . . . . . 95
Data View Windo w . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 96
Database Designer . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 97
SQL Edito r . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 98
T-SQL Debugger . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 98
Query Designer . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 99
Data Repo rter Designer . . . . . . . . . . . . . . . . . . . . . . . . . . 100
UserCo nnec tio n Designer . . . . . . . . . . . . . . . . . . . . . . . . . 100

Part II: Beginning Database Programming

103

Chapter 7: Codeless Database Programming . . . . . . . . . . . . . . 105
Data Binding . . . . . . . . . . . . . . . .
What is data binding? . . . . . . .
Ho w do es data binding wo rk? . .
Co nnec ting to the database . . . .
Intrinsic bo und c o ntro ls . . . . . .
Ac tiveX bo und c o ntro ls . . . . . .
Building the Co deless Pro gram . . . . .
Preparing yo ur pro jec t . . . . . .
Co nfiguring the ADO Data Co ntro l
Adding bo und c o ntro ls . . . . . .
Testing yo ur pro gram . . . . . . .
Finishing yo ur pro gram . . . . . .

.
.
.
.
.
.
.
.
.
.
.
.

.
.
.
.
.
.
.
.
.
.
.
.

.
.
.
.
.
.
.
.
.
.
.
.

.
.
.
.
.
.
.
.
.
.
.
.

.
.
.
.
.
.
.
.
.
.
.
.

.
.
.
.
.
.
.
.
.
.
.
.

.
.
.
.
.
.
.
.
.
.
.
.

.
.
.
.
.
.
.
.
.
.
.
.

.
.
.
.
.
.
.
.
.
.
.
.

.
.
.
.
.
.
.
.
.
.
.
.

.
.
.
.
.
.
.
.
.
.
.
.

.
.
.
.
.
.
.
.
.
.
.
.

.
.
.
.
.
.
.
.
.
.
.
.

.
.
.
.
.
.
.
.
.
.
.
.

.
.
.
.
.
.
.
.
.
.
.
.

.
.
.
.
.
.
.
.
.
.
.
.

.
.
.
.
.
.
.
.
.
.
.
.

.
.
.
.
.
.
.
.
.
.
.
.

.
.
.
.
.
.
.
.
.
.
.
.

.
.
.
.
.
.
.
.
.
.
.
.

105
105
106
106
107
107
108
108
109
113
114
114

xxi

xxii

Visual Basic 6 Database Programming Bible

Chapter 8: M ore About Bound Controls . . . . . . . . . . . . . . . . . 119
Bo und Co ntro ls Revisited . . . . . . .
Key pro perties . . . . . . . . . .
Key metho ds . . . . . . . . . . .
Key events . . . . . . . . . . . . .
Data validatio n . . . . . . . . . .
Fo rmatting data . . . . . . . . . .
Using the Pic ture and Image Co ntro ls
Using the Masked Edit Co ntro l . . . .
Key pro perties . . . . . . . . . .
Creating an input mask . . . . .
Pro mpting the user . . . . . . . .
Database c o nsideratio ns . . . .
Using the DateTimePic ker Co ntro l . .
Key pro perties . . . . . . . . . .
Cho o sing a user interfac e . . . .
Using the DataCo mbo Co ntro l . . . . .
Key pro perties . . . . . . . . . .
Key metho ds . . . . . . . . . . .
Co nfiguring the c o ntro l . . . . .
Selec ting fro m a list . . . . . . .
Translating a value . . . . . . . .

.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.

.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.

.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.

.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.

.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.

.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.

.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.

.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.

.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.

.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.

.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.

.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.

.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.

.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.

.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.

.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.

.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.

.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.

.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.

.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.

.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.

119
119
119
120
121
125
127
127
128
129
130
131
131
131
134
135
135
136
137
137
137

Chapter 9: Programming with Data Environments . . . . . . . . . . 141
The Data Enviro nment Designer . . . . . . . . .
Enabling the Data Enviro nment Designer .
Explo ring the Data Enviro nment Designer
Data Enviro nment building blo c ks . . . . .
Co nnec ting to Yo ur Database . . . . . . . . . . .
Setting Co nnec tio n pro perties . . . . . . .
Selec ting an OLE DB pro vider . . . . . . .
Entering c o nnec tio n info rmatio n . . . . . .
Creating Co mmands with the Designer . . . . .
Adding a c o mmand . . . . . . . . . . . . .
Setting general c o mmand pro perties . . .
Setting parameters . . . . . . . . . . . . . .
Setting advanc ed pro perties . . . . . . . .
Saving the Co mmand . . . . . . . . . . . .
Adding a Child Co mmand . . . . . . . . . .
Inserting a sto red pro c edure . . . . . . . .
Building Pro grams with the Designer . . . . . .
Drawing c o ntro ls . . . . . . . . . . . . . . .
Setting o ptio ns . . . . . . . . . . . . . . . .

.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.

.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.

.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.

.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.

.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.

.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.

.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.

.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.

.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.

.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.

.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.

.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.

.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.

.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.

.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.

141
142
142
144
145
146
146
146
147
148
148
149
151
153
154
157
158
158
160

Contents

Data Enviro nment RunTime Objec t Mo del . . .
DataEnviro nment pro perties . . . . . . . .
DataEnviro nment metho ds . . . . . . . . .
Data Enviro nment events . . . . . . . . . .
Viewing Databases with the Data View Windo w
Co nfiguring the Data View Windo w . . . .
Wo rking with database diagrams . . . . . .
Wo rking with tables . . . . . . . . . . . . .
Wo rking with views . . . . . . . . . . . . .
Wo rking with sto red pro c edures . . . . . .

.
.
.
.
.
.
.
.
.
.

.
.
.
.
.
.
.
.
.
.

.
.
.
.
.
.
.
.
.
.

.
.
.
.
.
.
.
.
.
.

.
.
.
.
.
.
.
.
.
.

.
.
.
.
.
.
.
.
.
.

.
.
.
.
.
.
.
.
.
.

.
.
.
.
.
.
.
.
.
.

.
.
.
.
.
.
.
.
.
.

.
.
.
.
.
.
.
.
.
.

.
.
.
.
.
.
.
.
.
.

.
.
.
.
.
.
.
.
.
.

.
.
.
.
.
.
.
.
.
.

.
.
.
.
.
.
.
.
.
.

.
.
.
.
.
.
.
.
.
.

161
161
162
163
163
164
164
165
166
167

Chapter 10: Building Reports with the M icrosoft Data
Report Designer . . . . . . . . . . . . . . . . . . . . . . . 169
Intro duc ing the Mic ro so ft Data Repo rt . . .
Using the Data Repo rt Designer . . . . . . .
Getting yo ur data . . . . . . . . . . . .
Building a data repo rt’s struc ture . .
Plac ing c o ntro ls o n yo ur repo rt . . .
Pro gramming Yo ur Repo rt . . . . . . . . . .
Previewing a repo rt . . . . . . . . . .
Printing a Repo rt . . . . . . . . . . . .
Expo rting repo rts . . . . . . . . . . .
Trac king async hro no us ac tivity . . .
The Data Repo rt o bjec t mo del . . . . . . .
DataRepo rt pro perties . . . . . . . . .
DataRepo rt metho ds . . . . . . . . . .
Key DataRepo rt events . . . . . . . .
Co ntro ls c o llec tio n pro perties . . . .
Expo rtFo rmat o bjec t pro perties . . .
Expo rtFo rmats c o llec tio n pro perties
Expo rtFo rmats c o llec tio n metho ds .
RptErro r o bjec t pro perties . . . . . .
RptFunc tio n c o ntro l pro perties . . .
RptImage c o ntro l pro perties . . . . .
RptLabel c o ntro l pro perties . . . . .
RptLine c o ntro l pro perties . . . . . .
RptShape c o ntro l pro perties . . . . .
RptTextBo x c o ntro l pro perties . . . .
Sec tio n o bjec t pro perties . . . . . . .
Sec tio ns c o llec tio n pro perties . . . .

.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.

.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.

.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.

.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.

.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.

.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.

.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.

.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.

.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.

.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.

.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.

.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.

.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.

.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.

.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.

.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.

.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.

.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.

169
170
170
170
172
176
176
177
178
179
179
179
181
182
184
184
184
185
187
187
189
190
192
193
194
195
195

xxiii

xxiv

Visual Basic 6 Database Programming Bible

Part III: Hardcore ADO

199

Chapter 11: The ADO Object M odel . . . . . . . . . . . . . . . . . . . 201
Intro duc ing Ac tiveX Data Objec ts 2.5 . . . .
The ADO o bjec t mo del . . . . . . . . .
New in ADO 2.5 . . . . . . . . . . . . . .
Intro duc ing Ac tiveX Data Objec ts Extensio ns
Basic ADO Pro gramming . . . . . . . . . . . .
Co nnec ting to the data so urc e . . . . .
Exec uting a c o mmand . . . . . . . . . .
Playing with Rec o rdsets . . . . . . . . .

.
.
.
.
.
.
.
.

.
.
.
.
.
.
.
.

.
.
.
.
.
.
.
.

.
.
.
.
.
.
.
.

.
.
.
.
.
.
.
.

.
.
.
.
.
.
.
.

.
.
.
.
.
.
.
.

.
.
.
.
.
.
.
.

.
.
.
.
.
.
.
.

.
.
.
.
.
.
.
.

.
.
.
.
.
.
.
.

.
.
.
.
.
.
.
.

.
.
.
.
.
.
.
.

.
.
.
.
.
.
.
.

.
.
.
.
.
.
.
.

.
.
.
.
.
.
.
.

.
.
.
.
.
.
.
.

201
201
203
204
207
207
207
208

Chapter 12: Connecting to a database . . . . . . . . . . . . . . . . . . 211
The Co nnec tio n Objec t . . . . . . .
Co nnec tio n o bjec t pro perties
Co nnec tio n o bjec t metho ds
Co nnec tio n o bjec t events . .
The Erro r Objec t . . . . . . . . . .
Erro r o bjec t pro perties . . .
The Erro rs Co llec tio n . . . . . . . .
Erro rs c o llec tio n pro perties
Erro rs c o llec tio n metho ds .
Co nnec ting To Database Server . .
Co nnec tio n strings . . . . . .
Opening a c o nnec tio n . . . .
Clo sing a c o nnec tio n . . . . .
Analyzing Erro rs . . . . . . . . . .
Watc hing c o nnec tio n ac tivity

. .
.
. .
. .
. .
. .
. .
. .
. .
. .
. .
. .
. .
. .
. .

.
.
.
.
.
.
.
.
.
.
.
.
.
.
.

.
.
.
.
.
.
.
.
.
.
.
.
.
.
.

.
.
.
.
.
.
.
.
.
.
.
.
.
.
.

.
.
.
.
.
.
.
.
.
.
.
.
.
.
.

.
.
.
.
.
.
.
.
.
.
.
.
.
.
.

.
.
.
.
.
.
.
.
.
.
.
.
.
.
.

.
.
.
.
.
.
.
.
.
.
.
.
.
.
.

.
.
.
.
.
.
.
.
.
.
.
.
.
.
.

.
.
.
.
.
.
.
.
.
.
.
.
.
.
.

.
.
.
.
.
.
.
.
.
.
.
.
.
.
.

.
.
.
.
.
.
.
.
.
.
.
.
.
.
.

.
.
.
.
.
.
.
.
.
.
.
.
.
.
.

.
.
.
.
.
.
.
.
.
.
.
.
.
.
.

.
.
.
.
.
.
.
.
.
.
.
.
.
.
.

.
.
.
.
.
.
.
.
.
.
.
.
.
.
.

.
.
.
.
.
.
.
.
.
.
.
.
.
.
.

.
.
.
.
.
.
.
.
.
.
.
.
.
.
.

.
.
.
.
.
.
.
.
.
.
.
.
.
.
.

.
.
.
.
.
.
.
.
.
.
.
.
.
.
.

.
.
.
.
.
.
.
.
.
.
.
.
.
.
.

.
.
.
.
.
.
.
.
.
.
.
.
.
.
.

211
211
214
217
223
223
223
224
224
225
225
227
231
231
232

Chapter 13: Using Commands and Stored Procedures . . . . . . . . 235
Intro duc ing the ADO Co mmand Objec t
The Co mmand Objec t . . . . . . . . . .
Co mmand o bjec t pro perties . . .
Co mmand bjec t metho ds . . . . .
The Parameter Objec t . . . . . . . . . .
Parameter o bjec t pro perties . . .
Parameter o bjec t metho ds . . . .
The Parameters Co llec tio n . . . . . . .
Parameters c o llec tio n pro perties
Parameters c o llec tio n metho ds .
Running SQL Statements . . . . . . . . .
Running a simple c o mmand . . .
Returning a Rec o rdset . . . . . . .
Running with parameters . . . . .

.
.
.
.
.
.
.
.
.
.
.
.
.
.

.
.
.
.
.
.
.
.
.
.
.
.
.
.

.
.
.
.
.
.
.
.
.
.
.
.
.
.

.
.
.
.
.
.
.
.
.
.
.
.
.
.

.
.
.
.
.
.
.
.
.
.
.
.
.
.

.
.
.
.
.
.
.
.
.
.
.
.
.
.

.
.
.
.
.
.
.
.
.
.
.
.
.
.

.
.
.
.
.
.
.
.
.
.
.
.
.
.

.
.
.
.
.
.
.
.
.
.
.
.
.
.

.
.
.
.
.
.
.
.
.
.
.
.
.
.

.
.
.
.
.
.
.
.
.
.
.
.
.
.

.
.
.
.
.
.
.
.
.
.
.
.
.
.

.
.
.
.
.
.
.
.
.
.
.
.
.
.

.
.
.
.
.
.
.
.
.
.
.
.
.
.

.
.
.
.
.
.
.
.
.
.
.
.
.
.

.
.
.
.
.
.
.
.
.
.
.
.
.
.

.
.
.
.
.
.
.
.
.
.
.
.
.
.

.
.
.
.
.
.
.
.
.
.
.
.
.
.

.
.
.
.
.
.
.
.
.
.
.
.
.
.

.
.
.
.
.
.
.
.
.
.
.
.
.
.

235
236
236
238
240
240
245
245
245
245
246
246
248
250

Contents

Sto red Pro c edures . . . . . . . . . . . . . .
Advantages o f sto red pro c edures . .
Sto red pro c edures and the Data View
Creating a Data Link . . . . . . . . . .
Creating a sto red pro c edure . . . . .
Debu