TEAMFLY Team-Fly ® C# Professional Projects This page intentionally left blank Geetanjali Arora Balasubramaniam Aiaswamy Nitin Pandey WITH C# Professional Projects Publisher: Stacy L. Hiquet Marketing Manager: Heather Buzzingham Managing Editor: Sandy Doell Editorial Assistant: Margaret Bauer Book Production Services: Argosy Cover Design: Mike Tanamachi ©2002 by Premier Press, Inc.All rights reserved. No part of this book may be reproduced or transmitted in any form or by any means, electronic or mechanical, including photocopying, recording, or by any information stor- age or retrieval system without written permission from Premier Press, except for the inclusion of brief quotations in a review. The Premier Press logo, top edge printing, and related trade dress are trademarks of Premier Press, Inc. and may not be used with- out written permission. All other trademarks are the property of their respective owners. Important: Premier Press cannot provide software support. Please contact the appropriate sof tware manufacturer’s technical support line or Web site for assistance. Premier Press and the author have attempted throughout this book to dis- tinguish proprietary trademarks from descriptive terms by following the cap- italization style used by the manufacturer. Information contained in this book has been obtained by Premier Press from sources believed to be reliable.However, because of the possibility of human or mechanical error by our sources, Premier Press, or others, the Publisher does not guarantee the accuracy, adequacy, or completeness of any informa- tion and is not responsible for any errors or omissions or the results obtained from use of such information. Readers should be particularly aware of the fact that the Internet is an ever-changing entity. Some facts may have changed since this book went to press. ISBN: 1-931841-30-6 Library of Congress Catalog Card Number: 2001096998 Printed in the United States of America 02 03 04 05 06 RI 10 9 8 7 6 5 4 3 2 1 About NIIT NIIT is a global IT solutions corporation with a presence in 38 countries. With its unique business model and technology-creation capabilities, NIIT delivers software and learning solutions to more than 1,000 clients across the world. The success of NIIT’s training solutions lies in its unique approach to education. NIIT’s Knowledge Solutions Business conceives, researches, and develops all of its course material. A rigorous instructional design methodology is followed to create engaging and compelling course content. NIIT trains over 200,000 executives and learners each year in information technology a reas using stand-up tra i n i n g, video-aided instru c t i on ,c omputer-based tra i n i n g (CBT), and Internet-based training (IBT). NIIT has been featured in the Guinness Book of World Records for the largest number of learners trained in one year! NIIT has developed over 10,000 hours of instructor-led training (ILT) and over 3,000 hours of Internet-based training and computer-based training. IDC ranked NIIT among the Top 15 IT training providers globally for the year 2000. Through the inno- vative use of training methods and its commitment to research and development, NIIT has been in the forefront of computer education and training for the past 20 years. Quality has been the prime focus at NIIT. Most of the processes are ISO-9001 certi- fied. It was the 12th company in the world to be assessed at Level 5 of SEI-CMM. NIIT’s Content (Learning Material) Development facility is the first in the world to be assessed at this highest maturity level. NIIT has strategic partnerships with compa- nies such as Computer Associates, IBM, Microsoft, Oracle, and Sun Microsystems. This page intentionally left blank About the Authors Geetanjali Arora is an instructional designer who has worked with the NIIT for almost two years.She has done several projects with the NIIT that include instructor- led training (ILT),computer-based training (CBT),and Web-based training (WBT). She has written on both technical and non-technical subjects. At the NIIT, Geentanjali’s responsibilities include scripting, construction, planning, and schedul- ing. She has also provided training on NexGen and Dreamweaver. Balasubramaniam Aiaswamy is a technical trainer and writer, an instructional designer, a subject matter expert (SME), and an ID reviewer with NIIT’s Knowledge Solutions Business division, which develops and reviews instructor-led training (ILT) products for various software and technologies.These technologies include Microsoft Visual InterDev 6.0, Microsoft Site Server 3.0 Commerce Edition, Microsoft Win- dows CE, Java 2 Micro Edition (J2ME), networking concepts, the installation and administration of a Layer 3 network, and Web security. He is both an MCSD and an MCP in Windows NT. Balasubramaniam has experience in teaching career programs at NIIT’s Career Education Group division. He has taught various technical subject areas including networking essentials, SQL Server 7.0, Microsoft Windows NT Server 4.0, Microsoft Visual Basic 6.0, Microsoft Visual C++ 4.0, Windows 32 API programming, HTML, Java, Unix, C, and C++. He has also set up and managed labs for students and administered Novell 3.11 and UNIX (SCO)–based networks. Nitin Pandey works with NIIT as a subject matter expert (SME) for learning con- tent developed on Microsoft technologies. Nitin has been involved in the develop- ment of WBTs and seminars for NIIT Online Ltd. and Microsoft. Nitin provides technical support to the development teams, develops sample applications, and pro- vides technical reviews of learning content. This page intentionally left blank Contents at a Glance Introduction. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . xxxi Part I Introduction to C# . . . . . . . . . . . . . . . . . . . . . . 1 1 Overview of the .NET Framework . . . . . . . . . . . . . . . . . . . 3 2 C# Basics . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 17 Part II Handling Data . . . . . . . . . . . . . . . . . . . . . . . . 41 3 Components of C# . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 43 4 More about Components . . . . . . . . . . . . . . . . . . . . . . . . . 67 5 Attributes and Properties. . . . . . . . . . . . . . . . . . . . . . . . . . 83 6 Threads . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 93 Part III Professional Project 1: Creating a Customer Maintenance Project. . 109 7 Project Case Study . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 113 8 Windows Forms and Controls. . . . . . . . . . . . . . . . . . . . . 141 9 Validations and Exception Handling . . . . . . . . . . . . . . . . 175 10 Database Interaction Using ADO.NET . . . . . . . . . . . . . 197 11 Crystal Reports. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 239 12 Deploying a Windows Application . . . . . . . . . . . . . . . . . 259 Part IV Professional Project 2: Creating the Employee Records System (ERS) Project. . . 293 13 Project Case Study and Design . . . . . . . . . . . . . . . . . . . . 297 14 Implementing the Business Logic . . . . . . . . . . . . . . . . . . 311 Part V Professional Project 3: Creating a Creative Learning Project . . . . . . 329 15 Project Case Study and Design . . . . . . . . . . . . . . . . . . . . 333 16 Implementing the Programming Logic . . . . . . . . . . . . . . 349 17 Interacting with a Microsoft Word Document and Event Viewer . . . . . . . . . . . . . . . . . . . . . 365 [...]... covering the basic concepts of C# These chapters enable readers to refresh basic programming concepts and understand how these concepts can be applied in C# Using the concepts covered in the overview sections, several professional projects have been created in the Professional Projects section These projects provide readers a hands-on approach to learning Visual C# The professional projects form a major part... with the knowledge of Visual C# concepts In addition to the concepts explained in the chapters, the book provides readers with several projects that enable them to create Windows applications, Web services, Web applications, and mobile Web applications.The book aims for providing the readers with extensive knowledge of C# so that they are able to develop live projects using C# The book is aimed at readers... 61 Interfaces 62 Contents Writing, Compiling, and Executing a C# Program 64 Writing a C# Program 64 Compiling a C# Program 65 Executing a C# Program 66 Summary 66 Chapter 4 More about Components ... major part of the book, covering both simple and complex concepts of the language Each professional project focuses on a specific C# concept and includes the case study for the project The case study of the project gives the readers an idea of the real-life situations where these projects can be applied In creating the projects, the simple-to-complex approach has been followed The book starts with creating... moves on to creating Web applications, Web services, and finally mobile Web applications In addition to the overview and the Professional Projects sections, the book includes the Beyond the Labs and Appendixes section.The Beyond the Labs section includes a chapter on the advanced C# concepts that have not been covered in the earlier sections This section introduces the concepts of messaging and COM+ Readers... 791 Contents PART IX BEYOND THE LABS 793 Chapter 34 Advanced C# Concepts 795 COM+ 796 What Is COM? 796 Windows DNA 802 Microsoft Transaction Server (MTS) 804 COM+ 805 NET... 15 Threads 15 Delegates 15 Summary 16 Chapter 2 C# Basics 17 Introduction to C# 18 Variables 18 Initializing Variables 19 Variable Modifiers...Contents at a Glance Professional Project 4: Creating an Airline Reservation Portal 395 18 19 20 21 22 23 24 25 26 Part VII Professional Project 5: Creating a Web Portal for a Bookstore 593 27 28 29 30 Part VIII Project Case Study and Design 717 Basics... Deploying a Windows Application 259 Introduction to Deploying a Windows Application 260 Deployment Projects Available in Visual Studio NET 261 Deployment Project Editors 279 Summary 291 Contents PART IV PROFESSIONAL PROJECT 2 293 Project 2 Creating the Employee Records System (ERS) Project 295... 353 Adding Code to the Exit Button 363 Summary 364 Chapter 17 Interacting with a Microsoft Word Document and Event Viewer 365 Interacting with a Microsoft Word Document 366 The Created Event 366 Adding Code to the Created Event 367 Overview of . Team-Fly ® C# Professional Projects This page intentionally left blank Geetanjali Arora Balasubramaniam Aiaswamy Nitin Pandey WITH C# Professional Projects Publisher: Stacy L various software and technologies.These technologies include Microsoft Visual InterDev 6.0, Microsoft Site Server 3.0 Commerce Edition, Microsoft Win- dows CE, Java 2 Micro Edition (J2ME), networking. technical subject areas including networking essentials, SQL Server 7.0, Microsoft Windows NT Server 4.0, Microsoft Visual Basic 6.0, Microsoft Visual C++ 4.0, Windows 32 API programming, HTML, Java,