Table Of ContentKarl Moore's
Visual Basic .NET:
The Tutorials
KARL MOORE
APress Media, LLC
Karl Moore's Visual Basic .NET: The Tutorials
Copyright © 2002 by Karl Moore
Originally published by Apress in 2002
All rights reserved. No part of this work may be reproduced or transmitted in any form or by any
means, electronic or mechanical, including photocopying, recording, or by any information
storage or retrieval system, without the prior written permission of the copyright owner and the
publisher.
ISBN 978-1-59059-021-8 ISBN 978-1-4302-1153-2 (eBook)
DOI 10.1007/978-1-4302-1153-2
Trademarked names may appear in this book. Rather than use a trademark symbol with every
occurrence of a trademarked name, we use the names only in an editorial fashion and to the
benefit of the trademark owner, with no intention of infringement of the trademark.
Technical Reviewers: Patricia Moore, Richard Costall, Ray Ellison, Erik Giggey, Donald Carter
Editorial Directors: Steve Anglin, Dan Appleman, Ewan Buckingham, Gary Cornell, Tony Davis,
Iason Gilmore, Dominic Shakeshaft, Iim Sumser, Karen Watterson, Iohn Zukowski
Managing Editor: Grace Wong
Project Manager: Alexa Stuart
Copy Editor: Tom Gillen
Production Editors: IanetVail and Grace Wong
Compositor: Impressions Book and Iournal Services, Inc.
Indexer: Ann Rogers
Cover Designer: Tom Debolski
Marketing Manager: Stephanie Rodriguez
The information in this book is distributed on an "as is" hasis, without warranty. Although every
precaution has been taken in the preparation of this work, neither the author nor Apress shall
have any liability to any person or entity with respect to any loss or damage caused or alleged to
be caused directly or indirectly by the information contained in this work.
Dedicated to my loving family: David, Patricia, and]o-Anne.
Oh, and my brain-without whom none of this would've been possible.
Brief Contents
Foreword ..............................................................x iii
About the Author .....................................................x v
About This Book .....................................................x vii
Tutorial 1: Beginning VB . NET ................................ .I
1.1 Programming, Visual Basic, and Everything ...................3
1. 2 Exploring Controls and Making Decisions ................... .23
1. 3 Variables and the Coolest Code .............................. .5 1
1. 4 Menus, Methods, Modules, and Multiple Forms ............... 71
1. 5 Errors, Setup, and Going from Here ..........................9 5
Tutorial 2: Doing Databases .................................1 17
2.1 Introducing Databases ........................................1 19
2. 2 Our Own Database and VB . NET ................................1 37
2. 3 Doing It Completely in Code ................................ .1 65
2.4 SQL Server, Web Applications, Transactions ••• Oh My! ..... 189
2. 5 Designing Reports and Going from Here .....................2 19
Tutorial 3: Working the Web .................................
241
3.1 The ASP. NET Revolution .......................................2 43
3.2 Ten Top Code Snippets You Can't Live Without .............2 77
3. 3 Authentication, Tips, Distribution, and More .............2 93
v
Brief Contents
Tutorial 4: Going Mobile ......................................
319
4.1 Introducing the Mobile Internet Toolkit ...................3 21
4.2 Your Device, Filters, Images, Memory, and More ...........3 43
Tutorial 5: Using Objects ....................................
367
5.1 Why Objects Are Important ....................................3 69
5.2 Objects in Real Life, Class Libraries, and More ..........3 91
Tutorial 6: Services Rendered ..............................
.417
6.1 Introducing the World of Web Services .................... .419
Tutorial 7: From VB6 to . NET ...............................
.445
7.1 All the Changes, Quickly .................................... .447
Tutorial 8: Tips and Techinques ...........................
.475
8.1 Beginner Tips and Techniques ............................... .477
8. 2 Intermediate Tips and Techniques .......................... .487
8.3 Advanced Tips and Techniques ................................5 05
Appendixes .........................................................
531
Appendix A Installing Visual Studio • NET .......................5 33
Appendix B Project Defaults ......................................5 36
Appendix C Standard Naming Conventions .........................5 42
Appendix D Windows Form Controls ................................ 545
Appendix E VB • NET Data Types ....................................5 48
Appendix F SQL Server Data Types ................................ 550
Index .................................................................5 53
vi
Contents
Foreword ..............................................................x iii
About the Author .....................................................x v
About This Book .....................................................x vii
Tutorial 1 Beginning VB . NET .........................1
1.1 Programming, Visual Basic, and Everything ......3
What Is VB . NET? .................................................... .4
Creating Your First Program ........................................5
Conclusion ...........................................................1 9
Review Sheet .........................................................2 1
1. 2 Exploring Controls and Making Decisions ....... .23
Exploring Controls ................................................. .23
Responding to Events ...............................................2 7
The Top Ten Controls .............................................. .29
Bringing It All Together ...........................................3 8
Making Decisions ................................................... .44
Conclusion .......................................................... .4 6
Review Sheet .........................................................4 9
1. 3 Variables and the Coolest Code ..................... 51
Using Variables .....................................................5 1
Time for a Test .....................................................5 6
And Now, the Cool Stuff! ...........................................5 7
Conclusion ...........................................................6 7
Review Sheet .........................................................6 9
vii
Contents
1.4 Menus, Methods, Modules,
and Multiple Forms .............................................
71
Expanding with Menus ...............................................7 1
Expanding with Forms ............................................... 77
Expanding with Methods .............................................8 1
Expanding with Functions ...........................................8 3
Methods, Modules, Mayhem-oh My! ..................................8 9
Conclusion ...........................................................9 2
Review Sheet .........................................................9 3
1. 5 Errors, Setup, and Going from Here ...............9 5
Handling the Errors ................................................9 5
Distributing Your Program ........................................1 00
FAQ ..................................................................1 08
Where to Go from Here .............................................1 11
Conclusion ..........................................................1 13
Review Sheet ....................................................... .1 15
Tutorial 2 Doing Databases .......................... 117
2.1 Introducing Databases .................................1 19
What Are Databases? ...............................................1 20
Choices, Choices .................................................. .1 22
Exploring Northwind ...............................................1 22
Doing the Data Bind ...............................................1 26
Conclusion ..........................................................1 34
Review Sheet .........................................................1 36
2. 2 Our Own Database and VB . NET .......................1 37
Creating Our Own Database ........................................1 37
Adding Relationships ..............................................1 41
Binding to a Windows Form ........................................1 45
Binding on the Web .................................................1 54
Using the Wizards ..................................................1 59
Conclusion ..........................................................1 61
Review Sheet ........................................................ .1 63
viii
Contents
2. 3 Doing It Completely in Code .........................
165
Talking the Talk ...................................................1 65
Cheating at SQL ....................................................1 70
Accessing in Code ..................................................1 71
Our Completely-in-Code Program ..................................1 72
Expanding with Relationships .....................................1 81
Conclusion ..........................................................1 86
Review Sheet .........................................................1 87
2.4 SQL Server, Web Applications,
Transactions . .. Oh My! .......................................
189
Joining the Big Boys ..............................................1 89
Creating a Server Database .......................................1 91
Creating a Transactional Database-Powered
Web Application ................................................2 00
And for My Next Trick ... Transactions! ......................... .210
Conclusion ..........................................................2 15
Review Sheet ........................................................ .2 17
2. 5 Designing Reports and Going from Here ..........
219
Reporting with Crystal ............................................2 19
FAQ ..................................................................2 32
Where to Go from Here ............................................ .236
Conclusion ..........................................................2 37
Review Sheet .........................................................1 39
Tutorial 3 Working the Web ......................... .
241
3 .1 The ASP. NET Revolution ................................2 43
How It All Works .................................................. .244
Creating Your First Site .........................................2 44
Getting Bigger and Better ....................................... .248
The Greatest Controls Ever Sold .................................2 58
Conclusion ..........................................................2 72
Review Sheet .........................................................2 73
ix
Contents
3.2 Ten Top Code Snippets You Can't
Live Without ....................................................
277
The Top Ten List ...................................................2 77
Quiz Time ...........................................................2 88
Conclusion ..........................................................2 90
Review Sheet .........................................................2 91
3.3 Authentication, Tips,
Distribution, and More .....................................
.293
Securing Your Sites .............................................. .293
Improving Your Site ...............................................3 03
Deployment ..........................................................3 09
FAQ ..................................................................3 11
Conclusion ..........................................................3 15
Review Sheet .........................................................3 17
Tutorial 4 Going Mobile ...............................
319
4.1 Introducing the Mobile Internet Toolkit .......
321
How Does It Work? ..................................................3 22
Creating Our First Mobile Application ..........................3 23
Exploring the Controls ............................................3 30
I'm Playing Around .................................................3 39
Conclusion ..........................................................3 40
Review Sheet .........................................................3 41
4.2 Your Device, Filters, Images,
Memory, and More ..............................................
343
Finding Out about Your Device ....................................3 43
A Word about Filters ..............................................3 48
Displaying Images, Using Filters ................................3 54
Do You Remember? ...................................................3 58
FAQ ..................................................................3 60
Conclusion ..........................................................3 63
Review Sheet .........................................................3 65
X