Microsoft Visual C# NET Step by Step - Version 2003 ISBN:0735619093 by John Sharp and Jon Jagger Microsoft Press © 2003 (635 pages) Teach yourself Visual C# NET version 2003—and start developing Microsoft NET– connected applications—one step at a time Master language fundamentals at your own pace and use the learn-by-doing exercises to dig in and code! CD Content Table of Contents Microsoft Visual C# NET Step by Step, Version 2003 Introduction Part I - Introducing Microsoft Visual C# and Visual Studio NET Chapter 1 Chapter 2 Chapter 3 Chapter 4 Chapter 5 Chapter 6 - Welcome to C# - Working with Variables, Operators, and Expressions - Writing Methods and Applying Scope - Using Decision Statements - Using Iteration Statements - Managing Errors and Exceptions Part II - Understanding the C# Language Chapter 7 - Creating and Managing Classes and Objects Chapter 8 - Understanding Values and References Chapter 9 - Creating Value Types with Enumerations and Struct Chapter 10 - Using Arrays and Collections Chapter 11 - Understanding Parameter Arrays Chapter 12 - Working with Inheritance Chapter 13 - Using Garbage Collection and Resource Managemen Part III - Creating Components Chapter 14 - Implementing Properties to Access Attributes Chapter 15 - Using Indexers Chapter 16 - Delegates and Events Chapter 17 - Operator Overloading Part IV - Working with Windows Applications Chapter 18 - Introducing Windows Forms Chapter 19 - Working with Menus Chapter 20 - Performing Validation Chapter 21 - Using Complex Controls Chapter 22 - Using the MDI, Windows, and Dialog Boxes Chapter 23 - Creating GUI Components Part V - Managing Data Chapter 24 - Using a Database Chapter 25 - Working with Data Binding and DataSets Chapter 26 - Handling XML Part VI - Building Web Applications Chapter 27 - Introducing ASP.NET Chapter 28 - Understanding Validation Controls Chapter 29 - Accessing Data with Web Forms Chapter 30 - Building ASP.NET Applications Chapter 31 - Building an XML Web Service Chapter 32 - Consuming a Web Service Index List of Sidebars CD Content Back Cover Build your dexterity with Visual C# and begin writing Microsoft.NET-connected applications—one step at a time! This practical, hands-on tutorial expertly guides you through the fundamentals—from learning Visual C# syntax to writing and running your first components, Web services, and applications Work at your own pace through easy-to-follow lessons and hands-on exercises to teach yourself essential techniques And stay ahead of the curve by working with real-world examples and best practices for Visual C# development Discover how to: Declare variables, define methods, and construct statements Handle and trap exceptions Use object-oriented techniques, such as inheritance and encapsulation Manage resources and use the garbage collector Build components, including properties, indexers, and events Define operators to enhance class usability Create GUI components and user controls Access data sources using Microsoft ADO.NET Write and manipulate XML documents Construct Web Forms that display large volumes of data Validate user input with Microsoft ASP.NET controls Write, test, and deploy Web services About the Authors John Sharp is a principal technologist at Content Master Ltd., a technical authoring company in the United Kingdom He develops and delivers instruction on everything from C#, J#, ASP.NET, and NET development to UNIX and Java programming Jon Jagger is a technology specialist for Content Master Ltd., specializing in C#, C++, Java, C, patterns, design, and general programming Jon is a U.K C++ standards panel member and a regular contributor to the ACCU Overload journal Microsoft Visual C# NET Step by Step, Version 2003 John Sharp Jon Jagger PUBLISHED BY Microsoft Press A Division of Microsoft Corporation One Microsoft Way Redmond, Washington 98052-6399 Copyright © 2003 by Microsoft Corporation 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 Library of Congress Cataloging-in-Publication Data Sharp, John, 1964Microsoft Visual C# NET Step by Step: Version 2003 / John Sharp, Jon Jagger p cm Includes index ISBN 0-7356-1909-3 C# (Computer program language) 2 Microsoft NET I Jagger, Jon, 1966- II Title QA76.73.C154S53 2003 005.2’768—dc21 2003041290 Printed and bound in the United States of America 1 2 3 4 5 6 7 8 9 QWT 8 7 6 5 4 3 Distributed in Canada by H.B Fenn and Company Ltd 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, JScript, Microsoft, Microsoft Press, Visual Basic, Visual C++, Visual C#, Visual Studio, Windows, and Windows NT 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 Robin Van Steenburgh Project Editor Denise Bankaitis Technical Editor Jim Fuchs Body Part No X09-45406 Acknowledgments This is the first book I have written, but I hope it’s not the last In undertaking this project, I never realized how much hard work it would be or how many people would be involved I am now enlightened! There are far too many to thank individually, but I would like to mention Karen Szall and Danielle Bird at Microsoft Press, and Joe Perez, Stephanie Edmundson, Elisabeth Knottingham, and Lonnon Foster, and thank them for their enduring patience with my endless typos, grammatical errors, and jargon I would also like to thank Suzanne Carlino, my project manager at Content Master, who beat me up and made sure I stuck to the schedule, and Robert Burbidge, who stepped in at the last minute and spent many thankless hours reviewing my work—and we are still friends! For the second edition of this book, I would also like to thank everyone who submitted reports to the Microsoft Press Web site identifying typos, mistakes, and making requests I hope we have incorporated everything! Furthermore, I am indebted to David Glanville, my project manager at Content Master, who guided me though the process of performing these updates and made sure I had the necessary time available (mainly after midnight!) Finally, I would like to acknowledge the support and help given to me by my family—to Diana, who had to put up with me creeping to bed at 2:00 in the morning on many occasions (at least some occurrences of which were related to my book-writing activities), to James, who kept asking “Is Daddy STILL on that computer?” and to Francesca, who just wants to see her name in a book And finally, finally,“Up the Gills!” John Sharp I’d like to dedicate this book to the five most important people in my life: my mother for having such a strong but gentle influence on me; my wife, Natalie, for making my life infinitely richer; and our three children, Ellie, Penny, and Patrick, who teach me important new things every day I’d also like to thank everyone who has helped me learn interesting things, particularly Douglas Adams, Christopher Alexander, Sean Corfield, Richard Gabriel, Kevlin Henney, John Holt, and David Pye Finally, I’d like to pay tribute to the elegance of the two-seater sports cars made by Marlin Engineering, the hilarity of the films made by Monty Python, the grass roots programming support provided by ACCU (http://www.accu.org), and the quality of life generated by the people of the village I live in Jon Jagger About the Authors John Sharp is a principal technologist at Content Master Ltd., a technical authoring company in the United Kingdom He develops and delivers instruction on everything from C#, J#, ASP.NET, and NET development to UNIX and Java programming John is deeply involved with Microsoft NET development, writing courses, building tutorials, and delivering conference presentations covering Microsoft Visual C# development and Microsoft ASP.NET He lives in Tetbury, Gloucestershire, in the United Kingdom Jon Jagger is a technology specialist for Content Master Ltd., specializing in C#, C++, Java, C, patterns, design, and general programming Jon is a UK C++ standards panel member and regular contributor to the ACCU Overload journal His interests include training excellence, design, simplicity, problem solving, and Monty Python (which he says is required knowledge for all software developers) Jon, his wife Natalie, and their three small children (Ellie, Penny, and Patrick) live in a delightful 104year-old house overlooking a 7-acre field of barley in a village called Trull (population 300) Keyhole Saw Saws have been in use since prehistoric times One dating from 1450 B.C., taken from an Egyptian tomb, doesn’t look much different from some saws in use today Different saws fill different needs For cutting holes, there is the compass saw or the shorter, thinner-bladed keyhole saw, which as the name implies is used to cut keyholes.* At Microsoft Press, we use tools to illustrate our books for software developers and IT professionals Tools very simply and powerfully symbolize human inventiveness They’re a metaphor for people extending their capabilities, precision, and reach From simple calipers and pliers to digital micrometers and lasers, these stylized illustrations give each book a visual identity, and a personality to the series With tools and knowledge, there’s no limit to creativity and innovation Our tagline says it all: the tools you need to put technology to work *The Great Tool Emporium © 1979 by David X Manners Published by Book Division, Times Mirror Magazines, Inc The manuscript for this book was prepared and submitted to Microsoft Press in electronic form Pages were composed by Microsoft Press using Adobe FrameMaker+SGML for Windows, with text in Sabon and display type in ITC Franklin Gothic Composed pages were delivered to the printer as electronic pre-press files Cover designer Methodologie, Inc Interior Graphic Designer James D Kramer Principal Compositor Kerri DeVault Interior Graphic Artist James D Kramer Principal Proofreader Victoria Thulman Indexer Lee Ross Tony Ross Chapter 21: Using Complex Controls Splitter Controls and Docking ListView and TreeView Synchronization Chapter 22: Using the MDI, Windows, and Dialog Boxes MDI and Toolbars Application and System Modal Dialog Boxes Chapter 23: Creating GUI Components Ambient Properties Toggle Buttons Chapter 24: Using a Database Firehose Cursors Closing Connections Chapter 25: Working with Data Binding and DataSets Typed DataSets Retrieving Large DataSets Integrity Rules and DataSets DataSet Update Events Chapter 26: Handling XML XML Schemas and DTDs Chapter 27: Introducing ASP.NET HTML Controls Event Processing and Round-Trips Chapter 28: Understanding Validation Controls Disabling Client Validation Dynamic HTML and Error Messages Chapter 29: Accessing Data with Web Forms DataGrid Styles Web Applications and Caching Chapter 30: Building ASP.NET Applications Other Data Controls Chapter 31: Building an XML Web Service RMI and IIOP Web Service Namespaces Chapter 32: Consuming a Web Service Web Services, Anonymous Access, and Authentication Monitoring Web Method Execution CD Content Following are select files from this book's Companion CD-ROM These files are for your personal use, are governed by the Books24x7 Membership Agreement, and are copyright protected by the publisher, author, and/or other third parties Unauthorized use, reproduction, or distribution is strictly prohibited Click on the link(s) below to download the files to your computer: File Description Microsoft Visual C# NET Step by Step- All CD Content Version 2003 Size 3,370,678 Chapter 1: Welcome to C# 70,812 Chapter 2: Working with Variables, Operators, and Expressions 80,017 Chapter 3: Writing Methods and Applying Scope 56,510 Chapter 4: Using Decision Statements 92,258 Chapter 5: Using Iteration Statements 93,635 Chapter 6: Managing Errors and Exceptions 51,237 Chapter 7: Creating and Managing Classes and Objects 31,122 Chapter 8: Understanding Values and References 34,291 Chapter 9: Creating Value Types with Enumerations and Structs 35,866 Chapter 10: Using Arrays and Collections 78,332 Chapter 11: Understanding Parameter Arrays 33,369 Chapter 12: Working with Inheritance 96,528 Using Garbage Collection and Resource Chapter 13: Management 46,529 Chapter 14: Implementing Properties to Access Attributes 42,361 Chapter 15: Using Indexers 60,737 Chapter 16: Delegates and Events 57,301 Chapter 17: Operator Overloading 71,767 Chapter 18: Introducing Windows Forms 325,002 Chapter 19: Working with Menus 464,249 Chapter 20: Performing Validation 110,570 Chapter 21: Using Complex Controls 118,403 Chapter 22: Using the MDI, Windows, and Dialog Boxes 43,127 Chapter 23: Creating GUI Components 97,802 Chapter 24: Using a Database 98,861 Chapter 25: Working with Data Binding and DataSets 182,196 Chapter 26: Handling XML 69,816 Chapter 27: Introducing ASP.NET 26,998 Chapter 28: Understanding Validation Controls 43,043 Chapter 29: Accessing Data with Web Forms 28,760 Chapter 30: Building ASP.NET Applications 73,940 Chapter 31: Building an XML Web Service 584,605 Chapter 32: Consuming a Web Service 81,407 Honest John Software Developers First Name Last Name Employee Id Position Role ... From the list of Currently Installed Programs, select Microsoft Visual C# NET Step By Step (2003 ) Sample Files Click Change/Remove The Confirm Uninstall dialog box opens Click OK to delete the practice files Click Finish to close the InstallShield Wizard dialog box... Windows 2000 Server with Service Pack 3 Microsoft Visual Studio NET 2003 Professional or Enterprise Edition (If you’re using the Standard Edition of Visual C# NET 2003 you can’t create controls, but you can complete the other... menu does not appear, double-click the My Computer icon on the desktop, double- click the icon for your CD-ROM drive, and then double-click StartCD.exe Click Install Practice Files Follow the onscreen instructions