TEAM LinG 01_575368 ffirs.qxd 10/7/05 10:46 PM Page i Professional VB 2005 01_575368 ffirs.qxd 10/7/05 10:46 PM Page ii 01_575368 ffirs.qxd 10/7/05 10:46 PM Page iii Professional VB 2005 Bill Evjen, Billy Hollis, Rockford Lhotka, Tim McCarthy, Rama Ramachandran, Kent Sharkey, Bill Sheldon 01_575368 ffirs.qxd 10/7/05 10:46 PM Page iv Professional VB 2005 Published by Wiley Publishing, Inc. 10475 Crosspoint Boulevard Indianapolis, IN 46256 www.wiley.com Copyright © 2006 by Wiley Publishing, Inc., Indianapolis, Indiana Published simultaneously in Canada ISBN-13: 978-0-7645-7536-5 ISBN-10: 0-7645-7536-8 Manufactured in the United States of America 10 9 8 7 6 5 4 3 2 1 1B/SW/RQ/QV/IN Library of Congress Cataloging-in-Publication Data: Professional Visual Basic 2005 / Bill Evjen ... [et al.]. p. cm. Includes index. ISBN-13: 978-0-7645-7536-5 (paper/website) ISBN-10: 0-7645-7536-8 (paper/website) 1. Microsoft Visual BASIC. 2. BASIC (Computer program language) 3. Microsoft .NET. I. Evjen, Bill. QA76.73.B3P7485 2005 005.2’768—dc22 2005012585 No part of this publication may be reproduced, stored in a retrieval system or transmitted in any form or by any means, electronic, mechanical, photocopying, recording, scanning or otherwise, except as permitted under Sections 107 or 108 of the 1976 United States Copyright Act, without either the prior written permission of the Publisher, or authorization through payment of the appropriate per-copy fee to the Copyright Clearance Center, 222 Rosewood Drive, Danvers, MA01923, (978) 750-8400, fax (978) 646-8600. Requests to the Publisher for permission should be addressed to the Legal Department, Wiley Publishing, Inc., 10475 Crosspoint Blvd., Indianapolis, IN 46256, (317) 572-3447, fax (317) 572-4355, or online at http://www.wiley.com/go/permissions. LIMIT OF LIABILITY/DISCLAIMER OF WARRANTY: THE PUBLISHER AND THE AUTHOR MAKE NO REPRESEN- TATIONS OR WARRANTIES WITH RESPECT TO THE ACCURACYOR COMPLETENESS OF THE CONTENTS OF THIS WORK AND SPECIFICALLY DISCLAIM ALL WARRANTIES, INCLUDING WITHOUT LIMITATION WAR- RANTIES OF FITNESS FOR APARTICULAR PURPOSE. NO WARRANTY MAY BE CREATED OR EXTENDED BY SALES OR PROMOTIONALMATERIALS. THE ADVICE AND STRATEGIES CONTAINED HEREIN MAYNOT BE SUIT- ABLE FOR EVERYSITUATION. THIS WORK IS SOLD WITH THE UNDERSTANDING THAT THE PUBLISHER IS NOT ENGAGED IN RENDERING LEGAL, ACCOUNTING, OR OTHER PROFESSIONAL SERVICES. IF PROFESSIONAL ASSISTANCE IS REQUIRED, THE SERVICES OF ACOMPETENT PROFESSIONALPERSON SHOULD BE SOUGHT. NEITHER THE PUBLISHER NOR THE AUTHOR SHALLBE LIABLE FOR DAMAGES ARISING HEREFROM. THE FACT THAT AN ORGANIZATION OR WEBSITE IS REFERRED TO IN THIS WORK AS ACITATION AND/OR A POTENTIALSOURCE OF FURTHER INFORMATION DOES NOT MEAN THAT THE AUTHOR OR THE PUBLISHER ENDORSES THE INFORMATION THE ORGANIZATION OR WEBSITE MAYPROVIDE OR RECOMMENDATIONS IT MAYMAKE. FURTHER, READERS SHOULD BE AWARE THAT INTERNET WEBSITES LISTED IN THIS WORK MAY HAVE CHANGED OR DISAPPEARED BETWEEN WHEN THIS WORK WAS WRITTEN AND WHEN IT IS READ. For general information on our other products and services please contact our Customer Care Department within the United States at (800) 762-2974, outside the United States at (317) 572-3993 or fax (317) 572-4002. Trademarks:Wiley, the Wiley logo, Wrox, the Wrox logo, Programmer to Programmer, and related trade dress are trade- marks or registered trademarks of John Wiley & Sons, Inc. and/or its affiliates, in the United States and other countries, and may not be used without written permission. Visual Basic is a registered trademark of Microsoft Corporation in the United States and/or other countries. All other trademarks are the property of their respective owners. Wiley Publishing, Inc., is not associated with any product or vendor mentioned in this book. Wiley also publishes its books in a variety of electronic formats. Some content that appears in print may not be available in electronic books. 01_575368 ffirs.qxd 10/7/05 10:46 PM Page v About the Authors Bill Evjen is an active proponent of .NET technologies and community-based learning initiatives for .NET. He has been actively involved with .NET since the first bits were released in 2000. In the same year, Bill founded the St. Louis .NET User Group (www.stlnet.org), one of the world’s first .NET user groups. Bill is also the founder and the executive director of the International .NET Association (INETA– www.ineta.org), which represents more than 375,000 members worldwide. Based in St. Louis, Missouri, Bill is an acclaimed author and speaker on ASP.NET and XMLWeb Services. He has written or coauthored more than 10 books, including Professional C# 2005and Professional ASP.NET 2.0(Wrox), XMLWeb Services for ASP.NET, ASP.NET Professional Secrets(Wiley), and more. Bill is a technical director for Reuters, the international news and financial services company, and he travels the world speaking to major financial institutions about the future of the IT industry. He gradu- ated from Western Washington University in Bellingham, Washington, with a Russian language degree. When he isn’t tinkering on the computer, he can usually be found at his summer house in Toivakka, Finland. You can reach Bill at [email protected]. To Kalle – Welcome to the family! Billy Hollisis coauthor of the first book ever published on Visual Basic .NET, VB.NET Programmingon the Public Beta(Wrox Press) as well as numerous other books and articles on .NET. Billy is a Microsoft regional director and an MVP, and he was selected as one of the original .NET “Software Legends.” He writes a monthly column for MSDN Online and is heavily involved in training, consultation, and soft- ware development on the Microsoft .NET platform, focusing on smart-client development and commer- cial packages. He frequently speaks at industry conferences such as Microsoft’s Professional Developer Conference, TechEd, and COMDES. Billy is a member of the INETAspeakers’ bureau and speaks at user group meetings all over the United States. Rockford Lhotkais the principal technology evangelist for Magenic Technologies (www.magenic.com), a company focused on delivering business value through applied technology and one of the nation’s premiere Microsoft Gold Certified Partners. Rockford is the author of several books, including Expert Visual Basic .NETand C# Business Objects. He is a Microsoft Software Legend, regional director, MVP, and INETAspeaker. He is a columnist for MSDN Online and contributing author for Visual Studio Magazine, and he regularly presents at major conferences around the world—including Microsoft PDC, Tech Ed, VS Live! and VS Connections. For more information go to www.lhotka.net. For my Mom and Dad, whose love and guidance have been invaluable in my life. Thank you! Tim McCarthyis a principal engineer at InterKnowlogy, where he architects and builds highly scalable n-tier web and smart-client applications utilizing the latest Microsoft platforms and technologies. Tim’s expertise covers a wide range of Microsoft technologies, including, but not limited to: .NET Framework (ASP.NET/Smart Clients/Web Services), Active Directory, UDDI, SQLServer, Windows SharePoint Services/SharePoint Portal Server 2003, and Service Oriented Architecture (SOA) applications. Tim has worked as a project technical lead/member as well as in a technical consulting role for several Fortune 500 companies. He has held the Microsoft Certified Solution Developer (MCSD) and Microsoft Certified Trainer (MCT) certifications for several years and was one of the first wave of developers to earn the Microsoft Certified Application Developer (MCAD) for .NET and MCSD for .NET certifications. He also holds the Microsoft Certified Database Administrator certification for SQLServer 2000. 01_575368 ffirs.qxd 10/7/05 10:46 PM Page vi Tim has been an author and technical reviewer for several books from Wrox Press and most recently was a lead author on Professional VB.NET 2003. His other books include Professional Commerce Server 2000, and Professional ADO 2.5 Programming. Tim is currently working as a lead author on the next edition of Professional VB.NET. Tim has written numerous articles for the Developer .NET Updatenewsletter, devel- oped packaged presentations for MSDN, and has written a whitepaper for Microsoft on using COM+ services in .NET. He has also written articles for SQLServer Magazineand Windows & .NET Magazine. Tim has spoken at technical conferences around the world and several San Diego area user groups (includ- ing both .NET and SQLServer groups) and he has been a regular speaker at the Microsoft Developer Days conference in San Diego for the last several years. Tim has also delivered MSDN webcasts, many of which were repeat requests from Microsoft. Tim also teaches custom .NET classes to companies in need of expert .NET mentoring and training. Tim holds a B.B.A. in marketing from the Illinois Institute of Technology as well as an M.B.A. in market- ing from National University. Before becoming an application developer, Tim was an officer in the United States Marine Corps. Tim’s passion for .NET is only surpassed by his passion for Notre Dame athletics. I dedicate this book to everybody in my family who supports me. Jasmine, some day you will be writing books, too! Rama Ramachandranis a software architect at DKR Capital, a major hedge fund company in Stamford, Connecticut. He is a Microsoft Certified Solutions Developer and Site-Builder and has excelled in designing and developing WinForms and Web applications using .NET, ASP.NET, Visual Basic and SQL Server. Rama has more than 15 years’ experience with all facets of the software development lifecycle and has cowritten Introducing .NET, Professional ASP Data Access, Professional Visual InterDev Programming (all Wrox Press), and four books on classic Visual Basic. Rama is also the “ASPPro” at Devx.com, where he maintains ASP-related columns. He teaches .NET Development and Web Development for Fairfield University’s master’s degree in software engineering, and at the University of Connecticut. You can reach Rama at [email protected]. This book is dedicated to my wife, Beena, and our children, Ashish and Amit. They make my life whole. I’m great at writing about technology but get tongue-tied trying to say how much I love and care about the three of you. I am grateful to our prayer-answering God for your laughing, mischievous, adoring lives. Thanks for being there, Beens. I love you. Kent Sharkey.Born in an igloo and raised by wolves in a strange realm called “Manitoba,” Kent Sharkey wandered the wilderness until found by a group of kind technical evangelists and migrated to Redmond. He now is content strategist (yeah, he doesn’t know what he’s supposed to do either) for ASP.NET content on MSDN. When not answering email he dreams of sleeping, complains to everyone around (come to think of it, he does that while answering email as well), and attempts to keep his house- mates (Babi, Cica, and Squirrel) happy. As with all else, to Margaret. Thank you. Bill Sheldonis a software architect and engineer originally from Baltimore, Maryland. Holding a degree in Computer Science from the Illinois Institute of Technology (IIT) and a Microsoft Certified Solution Developer (MCSD) qualification, Bill has been employed as an engineer since resigning his commission with the U.S. Navy following the first Gulf War. Bill is involved with the San Diego .NET User Group and writes for Windows and .NET magazines, including the twice monthly Developer .NET Updateemail newsletter. He is also a frequent online presenter for MSDN and speaks at live events such as Microsoft Developer Days. He lives with his wife, Tracie, in Southern California, where he is employed as a princi- pal engineer with InterKnowlogy. You can reach Bill at [email protected]. 01_575368 ffirs.qxd 10/7/05 10:46 PM Page vii Credits Acquisitions Editor Project Coordinator Katie Mohr Ryan Steffen Development Editors Graphics and Production Specialists Eileen Bien Calabro Carrie A. Foster Ami Frank Sullivan Lauren Goddard Denny Hager Technical Editor Barbara Moore Brian Patterson Lynsey Osborn Alicia South Production Editor Pamela Hanley Quality Control Technicians Laura Albert Copy Editor John Greenough Foxxe Editorial Services LeeannHarney Jessica Kramer Editorial Manager Brian H. Walls Mary Beth Wakefield Proofreading Vice President & Executive Group Publisher TECHBOOKS Production Services Richard Swadley Indexing Vice President and Publisher Broccoli Information Management Joseph B. Wikert 01_575368 ffirs.qxd 10/7/05 10:46 PM Page viii 02_575368 ftoc.qxd 10/7/05 10:47 PM Page ix Contents Introduction xxv Chapter 1: What Is Microsoft .NET? 1 What Is .NET? 1 A Broad and Deep Platform for the Future 2 What’s Wrong with DNA and COM? 2 An Overview of the .NET Framework 3 The Common Language Runtime 4 Key Design Goals 5 Metadata 7 Multiple-Language Integration and Support 7 A Common Type System 8 Namespaces 8 The Next Layer—The .NET Class Framework 8 What Is in the .NET Class Framework? 9 User and Program Interfaces 10 Windows Forms 11 Web Forms 11 Console Applications 12 Web Services 12 XML as the .NET Metalanguage 12 The Role of COM 13 No Internal Use of COM 13 Some Things Never Change . . . 13 .NET Drives Changes in Visual Basic 14 How .NET Affects You 14 A Spectrum of Programming Models 14 Reducing Barriers to Internet Development 15 Libraries of Prewritten Functionality 15 Easier Deployment 15 The Future of .NET 16 Major Differences in .NET 2.0 16 Summary 17