Microsoft ADO.NET Step by Step - Riordan_ Rebecca M_.pdf

(143538 KB) Pobierz
Microsoft ADO.Net Step By Step.doc
Microsoft ADO.Net - Step by Step
1
Microsoft ADO .NET Step by Step
by Rebecca M. Riordan
ISBN: 0735612366
Microsoft Press © 2002 (512 pages)
Learn to use the ADO.NET model to expand on data-bound Windows and
Web Forms, as well as how XML and ADO.NET intermingle.
Table of Contents
Microsoft ADO.NET Step by Step
Introduction
Part I - Getting Started with ADO.NET
Chapter 1 - Getting Started with ADO.NET
Part II - Data Providers
Chapter 2 - Creating Connections
Chapter 3 - Data Commands and the DataReader
Chapter 4 - The DataAdapter
Chapter 5 - Transaction Processing in ADO.NET
Part III - Manipulating Data
Chapter 6 - The DataSet
Chapter 7 - The DataTable
Chapter 8 - The DataView
Part IV - Using the ADO.NET Objects
Chapter 9 - Editing and Updating Data
Chapter 10 - ADO.NET Data-Binding in Windows Forms
Chapter 11 - Using ADO.NET in Windows Forms
Chapter 12 - Data-Binding in Web Forms
Chapter 13 - Using ADO.NET in Web Forms
Part V - ADO.NET and XML
Chapter 14 - Using the XML Designer
Chapter 15 - Reading and Writing XML
Chapter 16 - Using ADO in the .NET Framework
Index
List of Tables
List of Sidebars
Microsoft ADO.NET Step by Step
PUBLISHED BY
Microsoft Press
A Division of Microsoft Corporation
One Microsoft Way
Redmond, Washington 98052-6399
Copyright © 2002 by Rebecca M. Riordan
All rights reserved. No part of the contents of this book may be reproduced or transmitted
in any form
or by any means without the written permission of the publisher.
 
295670723.002.png
Microsoft ADO.Net - Step by Step
2
Library of Congress Cataloging-in-Publication Data
Riordan, Rebecca.
Microsoft ADO.NET Step by Step / Rebecca M. Riordan.
p. cm.
Includes index.
ISBN 0-7356-1236-6
1. Database design. 2. Object oriented programming (Computer
science) 3. ActiveX. I.
Title.
QA76.9.D26 R56 2002
005.75’85—dc21 2001054641
Printed and bound in the United States of America.
1 2 3 4 5 6 7 8 9 QWE 7 6 5 4 3 2
Distributed in Canada by Penguin Books Canada Limited.
A CIP catalogue record for this book is available from the British Library.
Microsoft Press books are available through booksellers and distributors worldwide. For
further information about international editions, contact your local Microsoft Corporation
office or contact Microsoft Press International directly at fax (425) 936-7329. Visit our
Web site at www.microsoft.com/mspress. Send comments to mspinput@microsoft.com .
ActiveX, IntelliSense, Internet Explorer, Microsoft, Microsoft Press, the .NET logo, Visual
Basic, Visual C#, and Visual Studio are either registered trademarks or trademarks of
Microsoft Corporation in the United States and/or other countries. Other product and
company names mentioned herein may be the trademarks of their respective owners.
The example companies, organizations, products, domain names, e-mail addresses,
logos, people, places, and events depicted herein are fictitious. No association with any
real company, organization, product, domain name, e-mail address, logo, person, place,
or event is intended or should be inferred.
Acquisitions Editor: Danielle Bird
Project Editor: Rebecca McKay
Body Part No. X08-05018
To my very dear friend, Stephen Jeffries
About the Author
Rebecca M. Riordan
With almost 20 years’ experience in software design, Rebecca M. Riordan has earned
an international reputation as an analyst, systems architect, and designer of database
and work -support systems.
She works as an independent consultant, providing systems design and consulting
expertise to an international client base. In 1998, she was awarded MVP status by
Microsoft in recognition of her work in Internet newsgroups. Microsoft ADO.NET Step by
Step is her third book for Microsoft Press.
Rebecca currently resides in New Mexico. She can be reached at
rebeccar@attglobal.net .
Introduction
Overview
ADO.NET is the data access component of Microsoft’s new .NET Framework. Microsoft
bills ADO.NET as “an evolutionary improvement” over previous versions of ADO, a claim
that has been hotly debated since its announcement. It is certainly true that the
ADO.NET object model bears very little relationship to earlier versions of ADO.
295670723.003.png
Microsoft ADO.Net - Step by Step
3
In fact, whether you decide to love it or hate it, one fact about the .NET Framework
seems undeniable: it levels the playing ground. Whether you’ve been at this computer
game longer than you care to talk about or you’re still sorting out your heaps and stacks,
learning the .NET Framework will require a major investment. We’re all beginners now.
So welcome to Microsoft ADO.NET Step by Step . Through the exercises in this book, I
will introduce you to the ADO.NET object model, and you’ll learn how to use that model
in developing data-bound Windows Forms and Web Forms. In later topics, we’ll look at
how ADO.NET interacts with XML and how to access older versions of ADO from the
.NET environment.
Since we’re all beginners, an exhaustive treatment would be, well, exhausting, so this
book is necessarily limited in scope. My goal is to provide you with an understanding of
the ADO.NET objects—what they are and how they work together. So fair warning: this
book will not make you an expert in ADO.NET. (How I wish it were that simple!)
What this book will give you is a road map, a fundamental understanding of the
environment, from which you will be able to build expertise. You’ll know what you need to
do to start building data applications. The rest will come with time and experience. This
book is a place to start.
Although I’ve pointed out language differences where they might be confusing, in order
to keep the book within manageable proportions I’ve assumed that you are already
familiar with Visual Basic .NET or Visual C# .NET. If you’re completely new to the .NET
environment, you might want to start with Microsoft Visual Basic .NET Step by Step by
Michael Halvorson (Microsoft Press, 2002) or Microsoft Visual C# .NET Step by Step by
John Sharp and Jon Jagger (Microsoft Press, 2002), depending on your language of
choice.
The exercises that include programming are provided in both Microsoft Visual Basic and
Microsoft C#. The two versions are identical (except for the difference between the
languages), so simply choose the exercise in the language of your choice and skip the
other version.
Conventions and Features in This Book
You’ll save time by understanding, before you start the lessons, how this book displays
instructions, keys to press, and so on. In addition, the book provides helpful features that
you might want to use.
 
Numbered lists of steps (1, 2, and so on) indicate hands-on exercises. A
rounded bullet indicates an exercise that has only one step.
 
Text that you are to type appears in bold .
 
Terms are displayed in italic the first time they are defined.
 
A plus sign (+) between two key names means that you must press those
keys at the same time. For example, “Press Alt+Tab” means that you hold down
the Alt key while you press Tab.
 
Notes labeled “tip” provide additional information or alternative methods for a
step.
 
Notes labeled “important” alert you to essential information that you should
check before continuing with the lesson.
 
Notes labeled “ADO” point out similarities and differences between ADO and
ADO.NET.
 
Notes labeled “Roadmap” refer to places where topics are discussed in depth.
 
You can learn special techniques, background information, or features related
to the information being discussed by reading the shaded sidebars that appear
throughout the lessons. These sidebars often highlight difficult terminology or
suggest future areas for exploration.
 
You can get a quick reminder of how to perform the tasks you learned by
reading the Quick Reference at the end of a lesson.
 
Microsoft ADO.Net - Step by Step
4
Using the ADO.NET Step by Step CD-ROM
The Microsoft ADO.NET Step by Step CD-ROM inside the back cover contains practice
files that you'll use as you complete the exercises in the book. By using the files, you
won't need to waste time creating databases and entering sample data. Instead, you can
concentrate on how to use ADO.NET. With the files and the step-by-step instructions in
the lessons, you'll also learn by doing, which is an easy and effective way to acquire and
remember new skills.
System Requirements
In order to complete the exercises in this book, you will need the following software:
  Microsoft Windows 2000 or Microsoft Windows XP
  Microsoft Visual Studio .NET
  Microsoft SQL Server Desktop Engine (included with Visual Studio .NET)
or Microsoft SQL Server 2000
This book and practice files were tested primarily using Windows 2000 and Visual Studio
.NET Professional; however, other editions of Visual Studio .NET, such as Visual Basic
.NET Standard and Visual C# .NET Standard, should also work.
Since Windows XP Home Edition does not include Internet Information Services (IIS),
you won't be able to create local ASP.NET Web applications (discussed in chapters 12
and 13 ) using Windows XP Home Edition. Windows 2000 and Windows XP Professional
do include IIS.
Installing the Practice Files
Follow these steps to install the practice files on your computer so that you can use them
with the exercises in this book.
1. Insert the CD in your CD-ROM drive.
A Start menu should appear automatically. If this menu does not appear,
double-click StartCD.exe at the root of the CD.
2. Click the Getting Started option.
3. Follow the instructions in the Getting Started document to install the
practice files and setup SQL Server 2000 or the Microsoft SQL Server
Desktop Engine (MSDE).
Using the Practice Files
The practice files contain the projects and completed solutions for the ADO.NET Step by
Step book. Folders marked 'Finish' contain working solutions. Folders marked 'Start'
contain the files needed to perform the exercises in the book.
Uninstalling the Practice Files
Follow these steps to remove the practice files from your computer.
1. Insert the CD in your CD-ROM drive.
A Start menu should appear automatically. If this menu does not appear,
double-click StartCD.exe at the root of the CD.
2. Click the Uninstall Practice Files option.
3. Follow the steps in the Uninstall Practice Files document to remove
the practice files.
Need Help with the Practice Files?
Every effort has been made to ensure the accuracy of the book and the contents of this
CD-ROM. As corrections or changes are collected for this book, they will be placed on a
Web page and any errata will also be integrated into the Microsoft online Help tool
known as the Knowledge Base. To view the list of known corrections for this book, visit
the following page:
http://support.microsoft.com/support/misc/kblookup.asp?id=Q314759
 
Microsoft ADO.Net - Step by Step
5
To search the Knowledge Base and review your support options for the book or CD-
ROM, visit the Microsoft Press Support site:
http://www.microsoft.com/mspress/support/
If you have comments, questions, or ideas regarding the book or this CD-ROM, or
questions that are not answered by searching the Knowledge Base, please send them to
Microsoft Press via e-mail to:
mspinput@microsoft.com
or by postal mail to:
Microsoft Press
Attn: Microsoft ADO.NET Step by Step Editor
One Microsoft Way
Redmond, WA 98052-6399
Please note that product support is not offered through the above addresses.
Part I: Getting Started with ADO.NET
Chapter List
Chapter 1: Getting Started with ADO.NET
Chapter 1: Getting Started with ADO.NET
Overview
In this chapter, you'll learn how to:
  Identify the primary objects that make up Microsoft ADO.NET are and how
they interact
  Create Connection and DataAdapter objects by using the DataAdapter
Configuration Wizard
  Automatically generate a DataSet
  Bind control properties to a DataSet
  Load data into a DataSet at run time
Like other components of the .NET Framework, ADO.NET consists of a set of objects
that interact to provide the required functionality. Unfortunately, this can make learning to
use the object model frustrating—you feel like you need to learn all of it before you can
understand any of it.
The solution to this problem is to start by building a conceptual framework. In other
words, before you try to learn the details of how any particular object functions, you need
to have a general understanding of what each object does and how the objects interact.
That's what we'll do in this chapter. We'll start by looking at the main ADO.NET objects
and how they work together to get data from a physical data store, to the user, and back
again. Then, just to whet your appetite, we'll work through building a set of objects and
binding them to a simple data form.
On the Fundamental Interconnectedness of All Things
In later chapters in this section, we’ll examine each object in the ADO.NET object model
in turn. At least in theory. In reality, because the objects are so closely interlinked, it’s
impossible to look at any single object in isolation.
295670723.001.png
Zgłoś jeśli naruszono regulamin