100% found this document useful (3 votes)
20 views55 pages

(Ebook) Practical Database Programming with Visual Basic.NET by Ying Bai ISBN 9780521712354, 9780521885188, 0521712351, 0521885183 download pdf

The document promotes the ebook 'Practical Database Programming with Visual Basic.NET' by Ying Bai, detailing its content and features for developing database programs using Visual Basic.NET. It includes links to download the ebook and other related titles, along with information about the author and the book's educational resources. The book covers practical applications and examples using popular database systems like Microsoft Access, SQL Server, and Oracle Database.

Uploaded by

radenamaror8
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
100% found this document useful (3 votes)
20 views55 pages

(Ebook) Practical Database Programming with Visual Basic.NET by Ying Bai ISBN 9780521712354, 9780521885188, 0521712351, 0521885183 download pdf

The document promotes the ebook 'Practical Database Programming with Visual Basic.NET' by Ying Bai, detailing its content and features for developing database programs using Visual Basic.NET. It includes links to download the ebook and other related titles, along with information about the author and the book's educational resources. The book covers practical applications and examples using popular database systems like Microsoft Access, SQL Server, and Oracle Database.

Uploaded by

radenamaror8
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 55

Visit https://ebooknice.

com to download the full version and


explore more ebooks

(Ebook) Practical Database Programming with Visual


Basic.NET by Ying Bai ISBN 9780521712354,
9780521885188, 0521712351, 0521885183

_____ Click the link below to download _____


https://ebooknice.com/product/practical-database-
programming-with-visual-basic-net-1367072

Explore and download more ebooks at ebooknice.com


Here are some recommended products that might interest you.
You can download now and explore!

(Ebook) Practical Database Programming with Visual


Basic.NET, 2nd Edition by Ying Bai ISBN 9781118162057,
1118162056
https://ebooknice.com/product/practical-database-programming-with-
visual-basic-net-2nd-edition-5473240

ebooknice.com

(Ebook) Practical Database Programming with Visual


Basic.NET, Second Edition by Ying Bai(auth.) ISBN
9781118162057, 9781118249833, 1118162056, 1118249836
https://ebooknice.com/product/practical-database-programming-with-
visual-basic-net-second-edition-4310366

ebooknice.com

(Ebook) Oracle Database Programming with Visual Basic.NET:


Concepts, Designs, and Implementations by Ying Bai ISBN
9781119734390, 1119734398
https://ebooknice.com/product/oracle-database-programming-with-visual-
basic-net-concepts-designs-and-implementations-35134992

ebooknice.com

(Ebook) SQL Server Database Programming With Visual


Basic.NET: Concepts, Designs and Implementations by Ying
Bai ISBN 9781119608509, 1119608503
https://ebooknice.com/product/sql-server-database-programming-with-
visual-basic-net-concepts-designs-and-implementations-11137566

ebooknice.com
(Ebook) Biota Grow 2C gather 2C cook by Loucas, Jason;
Viles, James ISBN 9781459699816, 9781743365571,
9781925268492, 1459699815, 1743365578, 1925268497
https://ebooknice.com/product/biota-grow-2c-gather-2c-cook-6661374

ebooknice.com

(Ebook) Practical Database Programming with Java by Ying


Bai ISBN 9780470889404, 0470889403

https://ebooknice.com/product/practical-database-programming-with-
java-2501314

ebooknice.com

(Ebook) Practical Database Programming with Java by Ying


Bai ISBN 9780470889404, 9781118104651, 9781118104668,
9781118104699, 0470889403, 111810465X, 1118104668,
1118104692
https://ebooknice.com/product/practical-database-programming-with-
java-47700340

ebooknice.com

(Ebook) Matematik 5000+ Kurs 2c Lärobok by Lena


Alfredsson, Hans Heikne, Sanna Bodemyr ISBN 9789127456600,
9127456609
https://ebooknice.com/product/matematik-5000-kurs-2c-larobok-23848312

ebooknice.com

(Ebook) SAT II Success MATH 1C and 2C 2002 (Peterson's SAT


II Success) by Peterson's ISBN 9780768906677, 0768906679

https://ebooknice.com/product/sat-ii-success-
math-1c-and-2c-2002-peterson-s-sat-ii-success-1722018

ebooknice.com
Practical Database Programming with Visual Basic NET
1st Edition Ying Bai Digital Instant Download
Author(s): Ying Bai
ISBN(s): 9780521885188, 0521885183
Edition: 1
File Details: PDF, 45.71 MB
Year: 2008
Language: english
This page intentionally left blank
Practical Database Programming with Visual Basic.NET

This book teaches readers how to develop professional and practi-


cal database programs and apply auto-generated codes using Visual
Basic.NET 2005 Design Tools and Wizards related to ADO.NET 2.0. The
code can also be used with the newly released Visual Basic.NET 2008.
Avoiding overly large blocks of code, the book shows a simple and easy
way to create database programs and enables the reader to build pro-
fessional and practical databases more efficiently. In addition to Design
Tools and Wizards, the runtime object method is discussed and ana-
lyzed to allow users to design and implement more sophisticated data-
driven applications with complicated coding techniques. Three popular
database systems – Microsoft Access, Microsoft SQL Server 2005, and
Oracle Database 10g Express Edition (XE) – are discussed in detail, with
practical examples and sample projects that will help students, program-
mers, and software engineers alike.
Sample code and additional exercise questions for students as well
as solutions and lecture slides for instructors are available via the Web
(www.cambridge.org/9780521712354).

Dr. Ying Bai is an associate professor in the Department of Computer


Science and Engineering at Johnson C. Smith University in Charlotte,
North Carolina. His special interests include computer architecture, soft-
ware engineering, programming languages, fuzzy logic controls, auto-
matic and robot controls, and robot calibrations. His industrial experience
includes positions at Motorola MMS, Schlumberger ATE Technology,
Immix TeleCom, and Lam Research. He is a senior member of the IEEE
and a member of the ACM. Dr. Bai has published numerous research
articles and five previous books on programming in the Windows envi-
ronment and fuzzy logic controls.
PRACTICAL DATABASE
PROGRAMMING WITH
VISUAL BASIC.NET

Ying Bai
Johnson C. Smith University

Satish Bhalla (Chapter Contributor)


Johnson C. Smith University
CAMBRIDGE UNIVERSITY PRESS
Cambridge, New York, Melbourne, Madrid, Cape Town, Singapore, São Paulo

Cambridge University Press


The Edinburgh Building, Cambridge CB2 8RU, UK
Published in the United States of America by Cambridge University Press, New York

www.cambridge.org
Information on this title: www.cambridge.org/9780521885188
© Ying Bai 2009

This publication is in copyright. Subject to statutory exception and to the


provision of relevant collective licensing agreements, no reproduction of any part
may take place without the written permission of Cambridge University Press.
First published in print format 2008

ISBN-13 978-0-511-45565-0 eBook (EBL)

ISBN-13 978-0-521-88518-8 hardback

ISBN-13 978-0-521-71235-4 paperback

Cambridge University Press has no responsibility for the persistence or accuracy


of urls for external or third-party internet websites referred to in this publication,
and does not guarantee that any content on such websites is, or will remain,
accurate or appropriate.
This book is dedicated to my wife, Yan Wang, and my daughter,
Xue Bai
Contents

Preface page xxvii


Acknowledgments xxix

1. Introduction 1
1.1 Outstanding Features of This Book 2
1.2 Whom This Book Is For 2
1.3 What This Book Covers 3
1.4 How This Book Is Organized and How to Use This Book 5
1.5 How to Use the Source Code and Sample Databases 6
1.6 Instructor and Customer Support 7
1.7 Homework Solutions 8

2. Introduction to Databases 10
2.1 What Are Databases and Database Programs? 11
2.1.1 File Processing System 11
2.1.2 Integrated Databases 12
2.2 Developing a Database 13
2.3 Sample Database 14
2.3.1 Relational Data Model 14
2.3.2 Entity-Relationship (ER) Model 17
2.4 Identifying Keys 18
2.4.1 Primary Key and Entity Integrity 18
2.4.2 Candidate Key 19
2.4.3 Foreign Keys and Referential Integrity 19
2.5 Define Relationships 19
2.5.1 Connectivity 19
2.6 ER Notation 23
2.7 Data Normalization 23
2.7.1 First Normal Form 24
2.7.2 Second Normal Form 24
2.7.3 Third Normal Form 25

vii
viii Contents

2.8 Database Components in Some Popular Databases 26


2.8.1 Microsoft Access Databases 28
2.8.1.1 Database File 29
2.8.1.2 Tables 29
2.8.1.3 Queries 29
2.8.2 SQL Server Databases 30
2.8.2.1 Data Files 30
2.8.2.2 Tables 30
2.8.2.3 Views 31
2.8.2.4 Stored Procedures 31
2.8.2.5 Keys and Relationships 31
2.8.2.6 Indexes 32
2.8.2.7 Transaction Log Files 32
2.8.3 Oracle Databases 33
2.8.3.1 Data files 33
2.8.3.2 Tables 33
2.8.3.3 Views 34
2.8.3.4 Stored Procedures 34
2.8.3.5 Indexes 35
2.8.3.6 Initialization Parameter Files 35
2.8.3.7 Control Files 35
2.8.3.8 Redo Log Files 36
2.8.3.9 Password Files 36
2.9 Create Microsoft Access Sample Database 36
2.9.1 Create the LogIn Table 36
2.9.2 Create the Faculty Table 37
2.9.3 Create the Other Tables 39
2.9.4 Create Relationships Among Tables 41
2.10 Create Microsoft SQL Server 2005 Sample Database 41
2.10.1 Create the LogIn Table 48
2.10.2 Create the Faculty Table 49
2.10.3 Create Other Tables 50
2.10.4 Create Relationships Among Tables 55
2.10.4.1 Create Relationship Between the LogIn
and Faculty Tables 56
2.10.4.2 Create Relationship Between the LogIn
and Student Tables 58
2.10.4.3 Create Relationship Between the Faculty
and Course Tables 59
2.10.4.4 Create Relationship Between the Student
and StudentCourse Tables 60
2.10.4.5 Create Relationship Between the Course
and StudentCourse Tables 61
2.11 Create Oracle 10g XE Sample Database 62
2.11.1 Create the LogIn Table 64
2.11.2 Create the Faculty Table 68
2.11.3 Create Other Tables 72
Contents ix

2.11.4 Create the Foreign Keys for Tables 74


2.11.4.1 Create the Foreign Key Between the LogIn
and Faculty Tables 74
2.11.4.2 Create the Foreign Key Between the LogIn
and Student Tables 79
2.11.4.3 Create the Foreign Key Between the Course
and Faculty Tables 80
2.11.4.4 Create the Foreign Key Between the
StudentCourse and Student Tables 80
2.11.4.5 Create the Foreign Key Between the
StudentCourse and Course Tables 82
2.12 Chapter Summary 84
2.13 Homework 84

3. Introduction to ADO.NET 87
3.1 ADO and ADO.NET 87
3.2 Overview of ADO.NET 88
3.3 The Architecture of ADO.NET 89
3.4 The Components of ADO.NET 91
3.4.1 The Data Provider 91
3.4.1.1 The ODBC Data Provider 92
3.4.1.2 The OLE DB Data Provider 93
3.4.1.3 The SQL Server Data Provider 93
3.4.1.4 The Oracle Data Provider 93
3.4.2 The Connection Class 94
3.4.2.1 The Open() Method of the Connection Class 96
3.4.2.2 The Close() Method of the Connection Class 97
3.4.2.3 The Dispose() Method of the Connection
Class 97
3.4.3 The Command and Parameter Classes 98
3.4.3.1 The Properties of the Command Class 99
3.4.3.2 The Constructors and Properties of the
Parameter Class 99
3.4.3.3 Parameter Mapping 100
3.4.3.4 The Methods of the ParameterCollection
Class 102
3.4.3.5 The Constructor of the Command Class 104
3.4.3.6 The Methods of the Command Class 105
3.4.3.6.1 The ExecuteReader Method 105
3.4.3.6.2 The ExecuteScalar Method 106
3.4.3.6.3 The ExecuteNonQuery Method 106
3.4.4 The DataAdapter Class 107
3.4.4.1 The Constructor of the DataAdapter Class 108
3.4.4.2 The Properties of the DataAdapter Class 108
3.4.4.3 The Methods of the DataAdapter Class 108
3.4.4.4 The Events of the DataAdapter Class 109
3.4.5 The DataReader Class 110
x Contents

3.4.6 The DataSet Component 113


3.4.6.1 The DataSet Constructor 115
3.4.6.2 The DataSet Properties 115
3.4.6.3 The DataSet Methods 115
3.4.6.4 The DataSet Events 115
3.4.7 The DataTable Component 118
3.4.7.1 The DataTable Constructor 119
3.4.7.2 The DataTable Properties 120
3.4.7.3 The DataTable Methods 120
3.4.7.4 The DataTable Events 122
3.5 Chapter Summary 124
3.6 Homework 125

4. Data Selection Query with Visual Basic.NET 129


PART I Data Query with Visual Basic.NET Design Tools
and Wizards 130
4.1 A Completed Sample Database Application Example 130
4.2 Visual Basic.NET 2005 Design Tools and Wizards 133
4.2.1 Data Components in the Toolbox Window 133
4.2.1.1 DataSet 134
4.2.1.2 DataGridView 135
4.2.1.3 BindingSource 135
4.2.1.4 BindingNavigator 136
4.2.1.5 TableAdapter 136
4.2.2 Data Sources Window 137
4.2.2.1 Add New Data Source 137
4.2.2.2 Data Source Configuration Wizard 138
4.2.2.3 DataSet Designer 143
4.3 Build a Sample Database Project – SelectWizard 144
4.3.1 Application User Interface 145
4.3.1.1 The LogIn Form 145
4.3.1.2 The Selection Form 147
4.3.1.3 The Faculty Form 147
4.3.1.4 The Course Form 148
4.3.1.5 The Student Form 149
4.4 Add and Utilize Visual Basic Wizards and Design Tools 151
4.4.1 Add and Configure a New Data Source 151
4.5 Query and Display Data Using the DataGridView
Control 155
4.5.1 View the Entire Table 155
4.5.2 View Each Record or the Specified Columns 157
4.6 Use DataSet Designer to Edit the Structure
of the DataSet 159
4.7 Bind Data to Associated Controls in the LogIn Form 161
4.8 Develop Code to Query Data Using the Fill() Method 165
4.9 Use Return a Single Value to Query Data for the LogIn
Form 168
Contents xi

4.10 Coding for the Selection Form 171


4.11 Bind Data to the Associated Controls in the Faculty Form 173
4.12 Develop Code to Query Data Using the Fill() Method 175
4.13 Display Pictures for the Faculty Form 178
4.13.1 Modify the Code for the Select Button Event
Procedure 179
4.13.2 Create a Function to Select the Matched Faculty
Image 180
4.14 Binding Data to Associated Controls in the Course Form 181
4.15 Develop Code to Query Data for the Course Form 185

PART II Data Query with Runtime Objects 189


4.16 Introduction to Runtime Objects 189
4.16.1 Procedure of Building a Data-Driven Application
Using Runtime Objects 191
4.17 Build a Microsoft Access Database Project –
AccessSelectRTObject 192
4.17.1 Query Data Using Runtime Objects for the LogIn
Form 192
4.17.1.1 Declare the Runtime Objects 193
4.17.1.2 Connect to the Data Source with the
Runtime Object 193
4.17.1.3 Coding for Method 1: Using DataSet-
TableAdapter to Query Data 194
4.17.1.4 Coding for Method 2: Using the
DataReader to Query Data 196
4.17.1.5 Clean Up the Objects Used 197
4.17.2 Coding for the Selection Form 199
4.17.3 Query Data Using Runtime Objects for the Faculty
Form 199
4.17.4 Query Data Using Runtime Objects for the Course
Form 207
4.17.5 Query Data Using Runtime Objects for the Student
Form 219
4.17.5.1 Coding for the Student Form Load Event
Procedure 219
4.17.5.2 Coding for the Student Select Button Event
Procedure 220
4.18 Build an SQL Server Database Project –
SQLSelectRTObject 226
4.18.1 Migrating from Access to SQL Server and Oracle
Databases 226
4.18.2 Query Data Using Runtime Objects for the LogIn
Form 229
4.18.2.1 Declare the Runtime Objects 230
4.18.2.2 Connect to the Data Source with the
Runtime Object 231
xii Contents

4.18.2.3 Coding for Method 1: Using the


TableAdapter to Query Data 232
4.18.2.4 Coding for Method 2: Using the
DataReader to Query Data 233
4.18.3 Coding for the Selection Form 235
4.18.4 Query Data Using Runtime Objects for the Faculty
Form 235
4.18.5 Query Data Using Runtime Objects for the Course
Form 239
4.18.6 Retrieve Data from Multiple Tables Using Joined
Tables 240
4.18.7 Query Data Using Runtime Objects for the Student
Form 245
4.18.8 Query Data Using Stored Procedures 246
4.18.8.1 Create the Stored Procedure 247
4.18.8.2 Call the Stored Procedure 248
4.18.8.3 Query Data Using Stored Procedures
for the Student Form 249
4.18.9 Query Data Using More Complicated Stored
Procedures 258
4.18.10 Query Data Using Nested Stored Procedures 263
4.19 Build a Sample Oracle Database Project –
OracleSelectRTObject 266
4.19.1 Install Oracle Database 10g Express Edition 266
4.19.2 Configure the Oracle Database Connection String 267
4.19.3 Query Data Using Runtime Objects for the LogIn
Form 268
4.19.3.1 Declare the Runtime Objects 269
4.19.3.2 Connect to the Data Source with the
Runtime Object 269
4.19.3.3 Coding for Method 1: Using the
TableAdapter to Query Data 270
4.19.3.4 Coding for Method 2: Using the
DataReader to Query Data 272
4.19.4 Coding for the Selection Form 273
4.19.5 Query Data Using Runtime Objects for the Faculty
Form 274
4.19.6 Query Data Using Runtime Objects for the Course
Form 277
4.19.7 Stored Procedures in the Oracle Database
Environment 280
4.19.7.1 The Syntax of Creating a Stored Procedure
in Oracle 280
4.19.7.2 The Syntax for Creating a Package in
Oracle 281
4.19.8 Create the Faculty Course Package for the Course
Form 283
Contents xiii

4.19.9 Query Data Using the Oracle Package for the


Course Form 286
4.20 Chapter Summary 294
4.21 Homework 295

5. Data Insertion with Visual Basic.NET 301


PART I Data Insertion with Visual Basic.NET Design Tools
and Wizards 302
5.1 Insert New Data into a Database 302
5.1.1 Insert New Records into a Database Using
the TableAdapter.Insert Method 303
5.1.2 Insert New Records into a Database Using the
TableAdapter.Update Method 304
5.2 Insert Data into the Access Database Using a Sample
Project – InsertWizard 304
5.2.1 Create a New Project Based on the SampleWizards
Project 305
5.2.2 Application User Interfaces 305
5.2.3 Create the Insert Faculty Form Window 305
5.2.4 Validate Data Before the Data Insertion 308
5.2.4.1 Visual Basic Collection and .NET Framework
Collection Classes 308
5.2.4.2 Validate Data Using the Generic Collection 309
5.2.5 Initialization and Termination Coding for the Data
Insertion 312
5.2.6 Build the Insert Query 314
5.2.6.1 Configure the TableAdapter and Build the
Data Insertion Query 314
5.2.7 Develop Code to Insert Data Using the
TableAdapter.Insert Method 315
5.2.8 Develop Code to Insert Data Using the
TableAdapter.Update Method 318
5.2.9 Validate Data After the Data Insertion 322
5.2.9.1 Develop Code to Retrieve the Newly Inserted
Records 323
5.2.9.2 Data Binding for All
Faculty-Information-Related TextBoxes 324
5.2.9.3 Develop Codes to Display the Newly Inserted
Faculty Photo 327
5.3 Insert Data into the SQL Server Database Using a Sample
Project – SQLInsertWizard 330
5.3.1 Modify the Existing Project to Create a New Data
Insertion Project 331
5.3.2 Create a New Form Window to Insert Data for the
Course Form 331
5.3.3 Project Initialization and Data Validation Before
Data Insertion 332
xiv Contents

5.3.4 Configure the TableAdapter and Build the Data


Insertion Query 336
5.3.5 Develop the Code to Insert Data Using the
TableAdapter.Insert Method 337
5.3.6 Perform Data Bindings for the Insert Course
Form Window 341
5.3.7 Develop the Code to Insert Data Using the
TableAdapter.Update Method 342
5.3.8 Data Validation for Newly Inserted Records 344
5.3.8.1 Develop Code to Perform the Data
Validation 345
5.3.8.2 Use the Select Button in the Course Form to
Perform the Data Validation 348
5.3.9 Insert Data into the Database Using Stored
Procedures 349
5.3.9.1 Create the Stored Procedure Using the
TableAdapter Query Configuration Wizard 350
5.3.9.2 Modify the Code to Perform the Data
Insertion Using the Stored Procedure 350
5.4 Insert Data into the Oracle Database Using a Sample
Project OracleInsertWizard 352

PART II Data Insertion with Runtime Objects 353


5.5 The Runtime Object Method 353
5.6 Insert Data into the SQL Server Database Using the
Runtime Object Method 355
5.6.1 Insert Data into the Faculty Table for the SQL Server
Database 355
5.6.1.1 Add a Data Insertion Form Window – Insert
Faculty Form 355
5.6.1.2 Develop the Code to Insert Data into the
Faculty Table 357
5.6.1.2.1 Validate Data Before the Data
Insertion and Startup Coding 357
5.6.1.2.2 Insert Data into the Faculty Table 361
5.6.1.2.3 Validate Data After the Data
Insertion 365
5.6.2 Insert a New Faculty Photo 369
5.6.3 Insert Data into the Microsoft Access Database
Using Runtime Objects 372
5.6.3.1 Modify the Imports Commands 373
5.6.3.2 Modify the Database Connection String 373
5.6.3.3 Modify the LogIn Query Strings 374
5.6.3.4 Modify the Faculty Query String 375
5.6.3.5 Modifications to Other Forms 377
5.6.4 Insert Data into the Oracle Database Using Runtime
Objects 379
Contents xv

5.6.4.1 Add the Reference and Modify the Imports


Commands 380
5.6.4.2 Modify the Database Connection String 380
5.6.4.3 Modify the LogIn Query Strings 381
5.6.4.4 Modify the Faculty Query String 383
5.6.4.5 Modifications to Other Forms 384
5.7 Insert Data into the Database Using Stored Procedures 386
5.7.1 Insert Data into the SQL Server Database Using
Stored Procedures 386
5.7.1.1 Add an Insert Data Form Window – Insert
Course Form 386
5.7.1.2 Develop Stored Procedures for the SQL
Server Database 388
5.7.1.3 Develop Code to Call Stored Procedures to
Insert Data into the Course Table 390
5.7.1.3.1 Validate Data Before the Data
Insertion and Startup Coding 390
5.7.1.3.2 Develop Code to Call Stored
Procedures 393
5.7.1.3.3 Validate Data After the Data
Insertion 396
5.7.2 Insert Data into the Oracle Database Using Stored
Procedures 397
5.7.2.1 Develop Stored Procedures in the Oracle
Database 398
5.7.2.2 Develop Code to Call Stored Procedures to
Insert Data into the Course Table 401
5.7.2.2.1 Validate Data Before the Data
Insertion and Startup Coding 401
5.7.2.2.2 Develop Code to Call Stored
Procedures 401
5.7.2.2.3 Validate Data After Data Insertion 405
5.8 Chapter Summary 405
5.9 Homework 406

6. Data Updating and Deleting with Visual Basic.NET 411


PART I Data Updating and Deleting with Visual Basic.NET
Design Tools and Wizards 412
6.1 Update or Delete Data from Databases 413
6.1.1 Updating and Deleting Data from Related Tables in
a DataSet 413
6.1.2 Update or Delete Data from a Database by Using
TableAdapter DBDirect Methods 414
6.1.3 Update or Delete Data from a Database by Using the
TableAdapter.Update Method 414
6.2 Update and Delete Data from an Access Database by
Using the Sample Project AccessUpdateDeleteWizard 415
xvi Contents

6.2.1 Create a New Project Based on the InsertWizard


Project 416
6.2.2 Application User Interfaces 416
6.2.2.1 Modify the Faculty Form Window 416
6.2.2.2 Bind Data for All Text Boxes of the Faculty
Form Window 417
6.2.3 Validate Data Before Data Updating and
Deleting 418
6.2.4 Build Update and Delete Queries 418
6.2.4.1 Configure TableAdapter and Build the Data
Updating Query 418
6.2.4.2 Build the Data Deletion Query 419
6.2.5 Develop Code to Update Data by Using the
TableAdapter DBDirect Method 420
6.2.5.1 Coding Modifications 420
6.2.5.2 Startup Coding 421
6.2.5.3 Update Coding 421
6.2.6 Develop Code to Update Data by Using the
TableAdapter.Update Method 423
6.2.7 Develop Code to Delete Data by Using the
TableAdapter DBDirect Method 425
6.2.8 Develop Code to Delete Data by Using the
TableAdapter.Update Method 426
6.2.9 Validate the Data After Data Updating and
Deleting 427
6.3 Update and Delete Data from a SQL Server Database by
Using the Sample Project SQLUpdateDeleteWizard 430
6.4 Update and Delete Data from an Oracle Database by
Using the Sample Project OracleUpdateDeleteWizard 433

PART II Data Updating and Deleting with Runtime Objects 434


6.5 The Runtime Object Method 434
6.6 Update and Delete Data from an SQL Server Database by
Using Runtime Objects 436
6.6.1 Update Data in the Faculty Table for the SQL Server
Database 436
6.6.1.1 Modify the Faculty Form Window 437
6.6.1.2 Modify the Original Coding in the Faculty
Form 438
6.6.1.2.1 Modify the Coding for the Faculty
Form 438
6.6.1.3 Develop Code to Update Data 441
6.6.1.4 Validate the Data Updating 443
6.6.2 Delete Data from the Faculty Table for the SQL
Server Database 443
6.6.2.1 Develop Code to Delete Data 444
6.6.2.2 Validate the Data Updating and Deleting 445
Contents xvii

6.7 Update and Delete Data for an Oracle Database by Using


Runtime Objects 447
6.7.1 Add the Oracle Namespace Reference and Modify
the Imports Command 449
6.7.2 Modify the Connection String and Query String for
the LogIn Form 449
6.7.2.1 Modify the Connection String in the Form
Load Event Procedure 449
6.7.2.2 Modify the SELECT Query String in the
TabLogIn Button Event Procedure 449
6.7.2.3 Modify the SELECT Query String in the
ReadLogIn Button Event Procedure 450
6.7.3 Modify the Query Strings for the Faculty Form 450
6.7.3.1 Modify the SELECT Query String for the
Select Button Event Procedure 450
6.7.3.2 Modify the UPDATE Query String for the
Update Button Event Procedure 451
6.7.3.3 Modify the DELETE Query String for the
Delete Button Event Procedure 451
6.7.4 Modify the Query Strings for the Course Form 451
6.7.4.1 Modify the SELECT Query String for the
Select Button Event Procedure 451
6.7.4.2 Modify the SELECT Query String for the
CourseList Event Procedure 452
6.7.5 Modify the Query Strings for the Insert Faculty
Form 452
6.7.6 Other Modifications 452
6.8 Update and Delete Data from a Database by Using Stored
Procedures 454
6.8.1 Update Data in an Access Database by Using Stored
Procedures 455
6.8.1.1 Modify the Existing Project 455
6.8.1.1.1 Modify the Imports Command and
Connection String 456
6.8.1.1.2 Modify the Query Strings for the
LogIn Button Event Procedures 456
6.8.1.1.3 Modify the Query Strings for the
Select and Update Button Event
Procedures 456
6.8.1.1.4 Other Modifications 457
6.8.1.2 Create Stored Procedures in the Access
Database 457
6.8.1.3 Call the Stored Procedure to Update the
Faculty Information 459
6.8.1.4 Confirm the Faculty Information Updating 460
6.8.2 Update Data for an SQL Server Database by Using
Stored Procedures 462
xviii Contents

6.8.2.1 Modify the Existing Project to Create a New


Project 462
6.8.2.2 Develop the Stored Procedure in the SQL
Server Database 465
6.8.2.3 Call the Stored Procedure to Perform the
Data Updating and Validate the Updated
Information 467
6.8.3 Update Data for an Oracle Database by Using Stored
Procedures 469
6.8.3.1 Modify the Existing Project to Create a New
Project 469
6.8.3.2 Develop the Stored Procedure in the Oracle
Database 472
6.8.3.3 Call the Stored Procedure to Perform the
Data Updating and Validation 475
6.8.4 Delete Data from the Oracle Database by Using
Stored Procedures 476
6.8.4.1 Create the Stored Procedure in the Oracle
Database 477
6.8.4.2 Develop the Code to Call the Stored
Procedure to Delete Records 480
6.9 Chapter Summary 481
6.10 Homework 482

7. Accessing Data in ASP.NET 487


7.1 What Is the .NET Framework? 488
7.2 What Is ASP.NET? 489
7.2.1 ASP.NET Web Application File Structure 491
7.2.2 ASP.NET Execution Model 491
7.2.3 What Really Happens When a Web Application Is
Executed? 492
7.2.4 The Requirements to Test and Run the Web Project 493
7.3 Develop an ASP.NET Web Application to Select Data
from SQL Server Databases 494
7.3.1 Create the User Interface – LogIn Form 495
7.3.2 Develop the Code to Access and Select Data from
the Database 496
7.3.3 Validate the Data in the Client Side 501
7.3.4 Create the Second User Interface – Selection Page 502
7.3.5 Develop the Code to Open the Other Pages 503
7.3.6 Create the Third User Interface – Faculty Page 505
7.3.7 Develop the Code to Select the Desired Faculty
Information 508
7.3.7.1 Develop the Code for the Page Load Event
Procedure 508
7.3.7.2 Develop the Code for the Select Button Event
Procedure 509
Contents xix

7.3.7.3 Develop the Code for Other Procedures 510


7.3.8 Create the Fourth User Interface – Course Page 514
7.3.8.1 The AutoPostBack Property of the List Box
Control 515
7.3.9 Develop the Code to Select the Desired Course
Information 516
7.3.9.1 Coding for the Course Page Loading and
Ending Event Procedures 517
7.3.9.2 Coding for the Select Button’s Click Event
Procedure 519
7.3.9.3 Coding for the SelectedIndexChanged Event
Procedure of the List Box Control 522
7.3.9.4 Coding for Other User-Defined Procedures 523
7.4 Develop an ASP.NET Web Application to Select Data
from Oracle Databases 525
7.4.1 Modify the Connection String in the LogIn
Page 526
7.4.2 Modify the Query String in the LogIn Page 527
7.4.3 Modify the Query String in the Faculty Page 528
7.4.4 Modify the Query String in the Course Page 530
7.5 Develop an ASP.NET Web Application to Insert Data into
SQL Server Databases 534
7.5.1 Create a New Web Page – Insert.aspx 534
7.5.2 Develop the Code to Perform the Data Insertion
Functionality 535
7.5.2.1 Develop the Code for the Page Load and
Back Button Event Procedures 536
7.5.2.2 Develop the Code for the Insert Button’s
Click Event Procedure 537
7.5.2.3 Develop the Code for Other Procedures 539
7.5.3 Validate the Data Insertion 539
7.6 Develop an ASP.NET Web Application to Insert Data into
Oracle Databases 544
7.6.1 Create the Insert Web Page and Develop the Code 545
7.6.1.1 Modifications to Imports Commands and
Page Load Event Procedure 546
7.6.1.2 Modifications to the Code of Subroutines and
Procedures 546
7.6.2 Modify the Code for the Faculty Page 548
7.7 Develop Web Applications to Update and Delete Data in
SQL Server Databases 551
7.7.1 Application User Interfaces 552
7.7.2 Modify the Code for the Faculty Page 552
7.7.3 Develop the Code for the Update Button Event
Procedure 553
7.7.4 Develop the Code for the Delete Button Event
Procedure 557
xx Contents

7.7.4.1 Relationships Between Five Tables in Our


Sample Database 557
7.7.4.2 Data Deletion Sequence 558
7.7.4.3 Use the Cascade Deleting Option to Simplify
the Data Deletion 559
7.7.4.4 Create the Stored Procedure to Perform the
Data Deletion 561
7.7.4.5 Develop the Code to Call the Stored
Procedure to Perform the Data Deletion 564
7.8 Develop an ASP.NET Web Application to Update and
Delete Data in Oracle Databases 567
7.8.1 Modify the Project to Perform the Data Updating 567
7.8.1.1 Modifications to the Select Button’s Click
Event Procedure 567
7.8.1.2 Add the Code to the Update Button and
UpdateParameters Procedures 568
7.8.2 Develop Stored Procedures to Perform the Data
Deletion 570
7.8.2.1 Delete an Existing Record from the Faculty
Table 571
7.8.2.2 Develop the Codes for the Delete Button’s
Click Event Procedure 572
7.8.2.3 Validate the Data Deleting Actions 574
7.8.2.4 The On Delete Cascade Constraint in the
Data Table 575
7.9 Chapter Summary 577
7.10 Homework 578

8. ASP.NET Web Services 582


8.1 What Are Web Services and Their Components? 583
8.2 Procedures to Build a Web Service 585
8.2.1 The Structure of a Typical Web Service Project 585
8.2.2 The Real Considerations When Building a Web
Service Project 586
8.2.3 Procedures to Build an ASP.NET Web Service 587
8.3 Build an ASP.NET Web Service Project to Access an SQL
Server Database 588
8.3.1 Files and Items Created in the New Web Service
Project 588
8.3.2 A Feeling of the HelloWorld Web Service Project as
It Runs 590
8.3.3 Modify the Default Web Service Project 594
8.3.4 Create a Base Class to Handle Error Checking for
Our Web Service 595
8.3.5 Create the Real Web Service Class 596
8.3.6 Add Web Methods into Our Web Service
Class 597
Contents xxi

8.3.7 Develop the Code for Web Methods to Perform the


Web Services 598
8.3.7.1 Web Service Connection Strings 598
8.3.7.2 Modify the Existing Web Method 600
8.3.7.3 Develop the Code to Perform the Database
Queries 602
8.3.7.4 Develop the Code for Subroutines Used in the
Web Method 604
8.3.8 Develop a Stored Procedure to Perform the Data
Query 607
8.3.8.1 Develop the Stored Procedure
WebSelectFacultySP 607
8.3.8.2 Add Another Web Method to Call the Stored
Procedure 608
8.3.9 Use DataSet as the Returning Object for the Web
Method 609
8.3.10 Build Windows-Based Web Service Clients to
Consume the Web Services 612
8.3.10.1 Create a Web Service Proxy Class 612
8.3.10.2 Develop the Graphical User Interface for
the Windows-Based Client Project 614
8.3.10.3 Develop the Code to Consume the Web
Service 616
8.3.10.3.1 Develop the Code for the
Form Load Event Procedure 617
8.3.10.3.2 Develop the Code for the Select
Button’s Click Event Procedure 618
8.3.10.3.3 Develop the Code for Other
Subroutines 619
8.3.10.3.4 Develop a Subroutine ShowFaculty
to Display the Faculty Image 621
8.3.11 Build Web-Based Web Service Clients to Consume
the Web Service 623
8.3.11.1 Create a New Web Site Project and Add an
Existing Web Page 624
8.3.11.2 Add a Web Service Reference and Modify
the Web Form Window 624
8.3.11.3 Modify the Code for the Related Event
Procedures 625
8.3.11.3.1 Modify the Code in the Page Load
Event Procedure 626
8.3.11.3.2 Modify the Code in the Select
Button Event Procedure 626
8.3.11.3.3 Add Three User-Defined
Subroutines 628
8.3.11.3.4 Modify the Code for the Back
Button Event Procedure 629
xxii Contents

8.3.12 Deploy the Completed Web Service to Production


Servers 630
8.3.12.1 Copy Web Service Files to the Virtual
Directory 631
8.3.12.2 Publish a Precompiled Web Service 632
8.4 Build an ASP.NET Web Service Project to Insert Data into
an SQL Server Database 633
8.4.1 Modify an Existing Web Service Project 633
8.4.2 Web Service Project Development Procedure 635
8.4.3 Develop and Modify the Code for the Code-Behind
Page 635
8.4.3.1 Develop and Modify the First Web Method –
SetSQLInsertSP 636
8.4.3.2 Develop the Second Web Method –
GetSQLInsert 640
8.4.3.3 Develop and Modify the Third Web Method –
SQLInsertDataSet 642
8.4.3.4 Develop the Fourth Web Method –
GetSQLInsertCourse 647
8.4.3.4.1 Create the Stored Procedure
WebSelectCourseSP 648
8.4.3.4.2 Develop the Code to Call This Stored
Procedure 649
8.4.4 Build Windows-Based Web Service Clients to
Consume the Web Services 653
8.4.4.1 Create a Web Service Proxy Class 653
8.4.4.2 Develop the Graphical User Interface for the
Client Project 654
8.4.4.3 Develop the Code to Consume the Web
Service 657
8.4.4.3.1 Develop the Code to Initialize and
Terminate the Client Project 657
8.4.4.3.2 Develop the Code to Insert a New
Course Record into the Database 658
8.4.4.3.3 Develop the Code to Perform the
Inserted Data Validation 662
8.4.4.3.4 Develop the Code to Get the
Detailed Information for a Specific
Course 666
8.4.5 Build Web-Based Web Service Clients to Consume
the Web Services 668
8.4.5.1 Create a New Web Site Project and Add an
Existing Web Page 669
8.4.5.2 Add a Web Service Reference and Modify the
Web Form Window 670
8.4.5.3 Modify the Code for the Related Event
Procedures 671
Contents xxiii

8.4.5.3.1 Modify the Code in the Page Load


Event Procedure 672
8.4.5.3.2 Develop Code for the Insert Button
Event Procedure 673
8.4.5.3.3 Develop Code for the TextChanged
Event Procedure of the CourseID
Text Box 674
8.4.5.3.4 Modify the Code in the Select
Button’s Click Event Procedure 675
8.4.5.3.5 Modify the Code in the
SelectedIndexChanged Event
Procedure 678
8.4.5.3.6 Modify the Code in the Back
Button’s Click Event Procedure 680
8.5 Build an ASP.NET Web Service to Update and Delete
Data in an SQL Server Database 682
8.5.1 Modify an Existing Web Service Project 682
8.5.2 Modify Related Web Methods 683
8.5.2.1 Modify the Web Method from
SetSQLInsertSP to SQLUpdateSP 684
8.5.2.2 Modify the Web Method GetSQLInsert to
GetSQLCourse 686
8.5.2.3 Modify the Web Method
GetSQLInsertCourse to
GetSQLCourseDetail 687
8.5.2.4 Add a New Web Method – SQLDeleteSP 689
8.5.3 Develop Two Stored Procedures –
WebUpdateCourseSP and WebDeleteCourseSP 691
8.5.3.1 Develop the Stored Procedure
WebUpdateCourseSP 691
8.5.3.2 Develop the Stored Procedure
WebDeleteCourseSP 693
8.6 Build Windows-Based Web Service Clients to Consume the
Web Services 702
8.6.1 Modifications to the File Folder and Project Files 702
8.6.2 Add a New Web Reference to Our Client Project 703
8.6.3 Modifications to the Graphical User Interface 704
8.6.4 Modifications to the Code for the Different Event
Procedures 705
8.6.4.1 Modify the Code for the Form Load Event
Procedure and Form-Level Variables 705
8.6.4.2 Develop the Code for the Update Button
Event Procedure 706
8.6.4.3 Develop the Code for the Delete Button
Event Procedure 707
8.6.4.4 Modify the Code for the Select Button Event
Procedure 708
xxiv Contents

8.6.4.5 Modify the Code for the


SelectedIndexChanged Event Procedure 709
8.7 Build Web-Based Web Service Clients to Consume the
Web Services 713
8.7.1 Create a New Web Site Project and Add an Existing
Web Page 714
8.7.2 Add a Web Service Reference and Modify the Web
Form Window 714
8.7.3 Modify the Code for the Related Event Procedures
and Subroutines 716
8.7.3.1 Modify the Code for the Page Load Event
Procedure 716
8.7.3.2 Develop Code for the Update Button Event
Procedure 716
8.7.3.3 Develop Code for the Delete Button’s Click
Event Procedure 717
8.7.3.4 Modify Code for the Select Button Event
Procedure and Related Subroutines 719
8.7.3.5 Modify Code for the SelectedIndexChanged
Event Procedure of the Course List Box
Control and Related Subroutines 720
8.8 Build an ASP.NET Web Service Project to Access an
Oracle Database 724
8.8.1 Build a Web Service Project –
WebServiceOracleSelect 725
8.8.2 Modify the Connection String 726
8.8.3 Modify the Namespace Directories 726
8.8.4 Modify the Web Method GetSQLSelect and Related
Subroutines 726
8.8.5 Modify the Web Method GetSQLSelectSP and
Related Subroutines 728
8.8.5.1 Modifications to the Stored Procedure
WebSelectFacultySP 729
8.8.5.2 Modifications to the Code for the Web
Method GetSQLSelectSP 733
8.8.6 Modify the Web Method GetSQLSelectDataSet 734
8.9 Build Web Service Clients to Consume the Web Service
WebServiceOracleSelect 739
8.10 Build an ASP.NET Web Service Project to Insert Data into
an Oracle Database 740
8.10.1 Build a Web Service Project –
WebServiceOracleInsert 740
8.10.2 Modify the Connection String 741
8.10.3 Modify the Namespace Directories 741
8.10.4 Modify the Web Method SetSQLInsertSP and
Related Subroutines 742
Contents xxv

8.10.5 Modify the Web Method GetSQLInsert and Related


Subroutines 744
8.10.6 Modify the Web Method SQLInsertDataSet 746
8.10.7 Modify the Web Method GetSQLInsertCourse and
Related Subroutines 748
8.11 Build Web Service Clients to Consume the Web Service
WebServiceOracleInsert 757
8.12 Build an ASP.NET Web Service to Update and Delete
Data in an Oracle Database 758
8.12.1 Build a Web Service Project –
WebServiceOracleUpdateDelete 758
8.12.2 Modify the Connection String 759
8.12.3 Modify the Namespace Directories 759
8.12.4 Modify the Web Method SQLUpdateSP and
Related Subroutines 760
8.12.4.1 Develop the Stored Procedure
UpdateCourse SP 762
8.12.5 Modify the Web Method GetSQLCourse and
Related Subroutines 765
8.12.6 Modify the Web Method GetSQLCourseDetail and
Related Subroutines 766
8.12.7 Modify the Web Method SQLDeleteSP 768
8.12.7.1 Develop the Stored Procedure
WebDeleteCourseSP 770
8.13 Build Web Service Clients to Consume the Web Service
WebServiceOracleUpdateDelete 774
8.14 Chapter Summary 775
8.15 Homework 776

Index 781
Preface

Databases have become an integral part of our modern-day life. We are an


information-driven society. Database technology has a direct impact on our daily
lives. Decisions are routinely made by organizations based on the information col-
lected and stored in databases. A record company may decide to market certain
albums in selected regions on the basis of teenagers’ music preferences. Grocery
stores display more popular items at eye level, and reorders are based on the inven-
tories taken at regular intervals. Other examples include patients’ records in hos-
pitals, bank customers’ account information, book orders by libraries, club mem-
berships, auto part orders, winter clothing stock in department stores, and many
more.
In addition to database management systems, in order to effectively apply and
implement databases in real industrial or commercial systems, a good graphical user
interface (GUI) is needed to allow users to access and manipulate their records
or data in databases. Visual Basic.NET is an ideal candidate to provide this GUI
functionality. Unlike other programming languages, Visual Basic.NET is easy to
learn and easy to understand, with a low learning curve. Beginning with Visual Stu-
dio.NET 2005, Microsoft integrated a few programming languages, such as Visual
C++, Visual Basic, C#, and Visual J#, into a dynamic model called the .NET
Framework that makes Internet and Web programming easy and simple. Any lan-
guage integrated in to this model can be used to develop professional and efficient
Web applications that can be used to communicate with others via the Internet.
ADO.NET and ASP.NET are two important submodels of the .NET Framework.
The former provides all the components, including the Data Providers, DataSet, and
DataTable, needed to access and manipulate data from different databases. The lat-
ter provides support to develop Web applications and Web services to allow users
to exchange information between clients and servers easily and conveniently.
This book is mainly designed for college students and software programmers
who want to develop practical and commercial database programming with Visual
Basic.NET 2005 and relational databases such as Microsoft Access, Microsoft SQL
Server 2005, and Oracle Database 10g Express Edition (XE). The book provides
a detailed description of the practical considerations and applications in database

xxvii
xxviii Preface

programming with Visual Basic 2005, along with authentic examples and detailed
explanations. More important, a new writing style implemented in this book, com-
bined with real examples, provides readers with a clear picture of how to handle
database programming issues in the Visual Basic.NET 2005 environment.
The outstanding features of this book include, but are not limited to, the follow-
ing:
1. A unique writing style is adopted to try to attract students’ or beginning pro-
grammers’ interest in learning and developing practical database programs,
and to avoid the headache caused by huge blocks of code, as is common in
traditional database programming books.
2. A real, completed sample database, CSE DEPT, with three versions
(Microsoft Access, SQL Server 2005, and Oracle Database 10g XE), is pro-
vided and used for the entire book. Step-by-step, detailed illustrations and
descriptions about how to design and build a practical relational database are
provided.
3. Both fundamental and advanced database programming techniques are cov-
ered for the convenience of both beginning students and experienced pro-
grammers.
4. Three types of popular databases are covered and discussed in detail with
practical sample examples: Microsoft Access, SQL Server 2005, and Oracle
Database 10g XE.
5. Various actual data providers are discussed and implemented in the sample
projects, such as the SQL Server and Oracle data providers. Instead of using
OLE DB to access the SQL Server or Oracle databases, real SQL Server
and Oracle data providers are utilized to connect to Visual Basic.NET 2005
directly to perform data operations.
6. It is a good textbook for college students and a good reference book for pro-
grammers, software engineers, and academic researchers.
I sincerely hope that this book will help readers or users develop and build pro-
fessional and practical database applications.
Acknowledgments

The first and most special thanks go to my wife, Yan Wang. I could not have finished
this book without her sincere encouragement and support.
I would also like to thank Dr. Satish Bhalla, who is the chapter contributor for
this book. He is a specialist in database programming and management, especially
in SQL Server, Oracle, and DB2. Dr. Bhalla spent a lot of time preparing materials
for Chapter 2, and he deserves thanks for this.
Many thanks to my editor, Heather Bergman, for helping to make this book a
reality. You would not have found this book in the market without her deep per-
spective and hard work. Thanks are also extended to the editing team of this book.
Without their contributions, it would have been impossible for this book to get pub-
lished.
Thanks should also be extended to the following book reviewers for their invalu-
able opinions on this book:
 Dr. Jifeng Xu, Research Scientist, The Boeing Company
 Dr. Xiaohong Yuan, Associate Professor, Department of Computer Science,
North Carolina A&T State University
 Dr. Daoxi Xiu, Application Analyst Programmer, North Carolina Administra-
tive Office of the Courts
 Dr. Dali Wang, Assistant Professor, Department of Physics and Computer Sci-
ence, Christopher Newport University
Last but not least, I thank all the people who supported me in finishing this book.

xxix
Practical Database Programming with Visual Basic.NET
1

Introduction

For years, during my teaching of database programming and Visual Basic.NET pro-
gramming at the college level, I found it so difficult to find a good textbook for
these topics that I had to combine a few different professional books together as
references to teach my course. Most of those books are specially designed for pro-
grammers or software engineers, cover a lot of programming strategies, and include
huge blocks of code, which cause terrible headaches for college students or begin-
ning programmers who are new to Visual Basic.NET and database programming. I
had to prepare my class presentations and figure out all the homework and exercises
for my students. I dreamed that one day I would find a good textbook that would be
suitable for college students or beginning programmers to help them learn and mas-
ter database programming with Visual Basic.NET easily and conveniently. Finally I
decided that I needed to do something about this dream myself after a long period
of waiting.
Another reason I had the idea for this book is the job market. As you know,
most industrial and commercial companies in the United States are database appli-
cation businesses, such as manufacturers, banks, hospitals, and retail stores. A
majority of them need professional people to develop and build database-related
applications, but not database management and design systems. To enable our stu-
dents to become good candidates for those companies, we need a book like this
one.
Unlike most of the database programming books in the current market, which
discuss and present database programming techniques with huge blocks of program-
ming code from the first page to the last page, this book uses a new writing style to
show readers, especially college students, how to develop professional and practi-
cal database programs in Visual Basic.NET by using Visual Basic.NET 2005 Design
Tools and Wizards related to ADO.NET 2.0 and how to apply code that is auto-
generated by using Wizards. With this new style, the headache caused by those huge
blocks of programming code is eliminated. Instead, a simple and easy way to create
database programs using the Design Tools can be developed to attract students’

1
2 Introduction

interest and enable students to build professional and practical databases in more
efficient and interesting ways.
There are so many different database programming books available in the mar-
ket, but one can rarely find a book like this one, which implements a new writing
style to hold students’ interest. To meet the needs of experienced or advanced stu-
dents and software engineers, the book contains two programming methods: the
fundamental database programming method using Visual Basic.NET 2005 Design
Tools and Wizards and the advanced database programming method using the
runtime object method. In the second method, all database-related objects are
created and applied while the project is running by utilizing a few blocks of
code.

1.1 OUTSTANDING FEATURES OF THIS BOOK


1. A new writing style is adopted to increase students’ or beginning program-
mers’ interest in learning and developing practical database programs and to
avoid the headache caused by the huge blocks of code found in traditional
database programming books.
2. A real, completed sample database, CSE DEPT, with three versions
(Microsoft Access, SQL Server 2005, and Oracle Database 10g XE), is pro-
vided and used throughout the book. A detailed illustration and description
of how to design and build a practical relational database is provided step by
step.
3. The book covers both fundamental and advanced database programming
techniques for the convenience of both beginning students and experienced
programmers.
4. Three types of popular databases are covered and discussed in detail, with
practical examples: Microsoft Access, Microsoft SQL Server 2005, and Oracle
Database 10g Express Edition (XE).
5. Various actual data providers are discussed and implemented in the sample
projects, such as SQL Server and Oracle data providers. Instead of using OLE
DB to access the SQL Server or Oracle databases, real SQL Server and Ora-
cle data providers are utilized to connect to Visual Basic.NET 2005 directly
to perform data operations.
6. The book provides homework and exercises, which allow users to practice
what they have learned by doing some exercises themselves.
7. It is a good textbook for college students and a good reference book for pro-
grammers, software engineers, and academic researchers.

1.2 WHOM THIS BOOK IS FOR


This book is designed for college students and software programmers who want
to develop practical and commercial database programming with Visual Basic.NET
and relational databases such as Access, SQL Server 2005, and Oracle Database 10g
XE. A fundamental knowledge and understanding of Visual Basic.NET and Visual
Studio.NET IDE is assumed.
1.3 What This Book Covers 3

1.3 WHAT THIS BOOK COVERS


Eight chapters are included in this book. The contents of each chapter can be sum-
marized as follows:

 Chapter 1 provides an introduction to and summary of the whole book.


 Chapter 2 provides a detailed discussion and analysis of the structure and com-
ponents of relational databases. Some key technologies in developing and
designing a database are also discussed in this part. The procedure and com-
ponents used to develop a practical relational database with three database ver-
sions, namely, Access, SQL Server 2005, and Oracle Database 10g XE, are ana-
lyzed in detail with real data tables in the sample database CSE DEPT.
 Chapter 3 provides an introduction to ADO.NET that includes the architec-
ture, organization, and components of ADO.NET. It also includes detailed
discussions and descriptions to give readers both fundamental and practical
ideas and pictures of how to use components in ADO.NET to develop pro-
fessional data-driven applications. Two ADO.NET architectures are discussed
to enable users to design and build their preferred projects on the basis of the
different organizations of ADO.NET. Four popular data providers, OLE DB,
ODBC, SQL Server, and Oracle, are discussed in detail. The basic ideas of
DataTable and DataSet are also analyzed and described with some real coding
examples.
 Starting with Chapter 4, actual database programming techniques of Visual
Basic.NET 2005, such as data selection queries, are provided and discussed.
This chapter comprises two parts: Part I contains detailed descriptions of how to
develop professional data-driven applications with the help of Visual Basic.NET
design tools and wizards and includes two real projects as examples. This part
contains a lot of hidden code that is created by Visual Basic.NET automat-
ically when using the design tools and wizards. Therefore the coding in this
part is very simple and easy. Part II covers an advanced technique, the run-
time object method, for developing and building professional data-driven appli-
cations. Detailed discussions and descriptions of how to build professional and
practical database applications using the runtime method are provided, along
with four real projects.
 Chapter 5 provides detailed discussions and analyses of three popular data inser-
tion methods with three different databases: Access, SQL Server 2005, and Ora-
cle.

1. Using TableAdapter’s DBDirect and TableAdapter.Insert() methods


2. Using the TableAdapter’s Update() method to insert new records that have
already been added to the DataTable in the DataSet
3. Using the Command object’s ExecuteNonQuery() method

This chapter is divided into two parts. Methods 1 and 2 are related to Visual
Basic.NET design tools and wizards and therefore are covered in Part I. The
third method is related to runtime objects and therefore is covered in Part II.
4 Introduction

Nine real projects are used to illustrate how to perform data insertion in three
different databases: Access, SQL Server 2005, and Oracle Database 10g XE.
Some professional and practical data validation methods are also discussed in
this chapter to confirm the data insertion.
 Chapter 6 provides discussions and analyses of three popular data updating and
deleting methods:

1. Using TableAdapter DBDirect methods, such as TableAdapter.Update()


and TableAdapter.Delete(), to update and delete data directly from the
database
2. Using the TableAdapter.Update() method to update and execute the asso-
ciated TableAdapter’ properties, such as UpdateCommand and DeleteCom-
mand, to save changes made in the table in the DataSet to the table in the
database
3. Using the runtime object method to develop and execute the Command
class’s ExecuteNonQuery() method to update or delete data from the
database directly

This chapter is also divided into two parts. Methods 1 and 2 are related to Visual
Basic.NET design tools and wizards and therefore are covered in Part I. The
third method is related to runtime objects and is covered in Part II. Seven real
projects are used to illustrate how to perform data updating and deleting in three
different databases: Access, SQL Server 2005, and Oracle Database 10g XE.
Some professional and practical data validation methods are also discussed in
this chapter to confirm the data updating and deleting actions. The key points to
remember when updating and deleting data in a relational database, such as the
order in which to execute data updating and deleting in parent and child tables,
are also discussed and analyzed.
 Chapter 7 provides introductions to and discussions about the development and
implementation of ASP.NET Web applications in the Visual Basic.NET 2005
environment. At the beginning of Chapter 7, detailed and complete descrip-
tions ASP.NET and Microsoft .NET Framework are provided. This part is
especially useful and important to students or programmers who do not have
any knowledge of or background in Web application development and imple-
mentation. Following the introduction section, a detailed discussion of how
to install and configure the environment to develop ASP.NET Web appli-
cations is provided. Some essential tools, such as the Web server, Internet
Information Services (IISs), and FrontPage Server Extension 2000 or 2002,
and the installation process for these tools are introduced and discussed in
detail. Starting with Section 7.3, the detailed development and building pro-
cesses of ASP.NET Web applications to access databases are discussed with six
real Web application projects. Two popular databases, SQL Server and Ora-
cle, are utilized as the target databases for these development and building
processes.
 Chapter 8 provides introductions to and discussions about the development
and implementation of ASP.NET Web services in the Visual Basic.NET
2005 environment. A detailed discussion and analysis of the structure and
1.4 How This Book Is Organized and How to Use This Book 5

components of Web services is provided at the beginning of this chapter. Two


popular databases, SQL Server and Oracle, are discussed and used for three
pairs of example Web service projects:

1. WebServiceSQLSelect and WebServiceOracleSelect


2. WebServiceSQLInsert and WebServiceOracleInsert
3. WebServiceSQLUpdateDelete and WebServiceOracleUpdateDelete

Each Web service contains different Web methods that can be used to access
different databases and perform the desired data actions, such as Select, Insert,
Update, and Delete, via the Internet. To consume those Web services, different
Web service client projects are also developed in this chapter. Both Windows-
based and Web-based Web service client projects are discussed and built for
each kind of Web service listed above. In all, eighteen projects, including the
Web service projects and the associated Web service client projects, are devel-
oped in this chapter. All projects have been debugged and tested and can be run
in Windows-compatible operating systems such as Windows 95, 98, 2000, XP,
and Vista.

1.4 HOW THIS BOOK IS ORGANIZED AND HOW TO USE THIS BOOK
This book is designed for both college students who are new to database program-
ming with Visual Basic.NET and professional database programmers who have
experience with this topic.
Chapters 2 and 3 provide the fundamentals of database structures and compo-
nents of ADO.NET. Chapters 4, 5, and 6 are each divided into two parts, a fun-
damental part and an advanced part. The data-driven applications developed with
design tools and wizards provided by Visual Basic.NET in the fundamental part
have less coding, and therefore are more suitable for students or programmers who
are new to database programming with Visual Basic.NET. Part II contains the run-
time object method and covers the development of code to perform different data
actions on the database. This method is more flexible and convenient for experi-
enced programmers because a lot of coding is required.
Chapters 7 and 8 give a full discussion and analysis the development and
implementation of ASP.NET Web applications and Web services. These technolo-
gies are necessary for students and programmers who want to develop and build
Web applications and Web services to access and manipulate data through the
Internet.
This book is organized so that it can be used at two levels, which are shown in
Figure 1.1.
It is highly recommended that undergraduate college students and beginning
programmers learn and understand the contents of Chapters 2 and 3 and Part I of
Chapters 4, 5, and 6 since those provide fundamental knowledge and techniques of
database programming with Visual Basic.NET 2005. Chapters 7 and 8 are optional
for instructors and depend on the time and schedule.
Step by step, a detailed description is given to illustrate how to design and set
up relationships between parent and child tables using the primary key and foreign
6 Introduction

Figure 1.1. Two levels in this book.

keys for Access, SQL Server 2005, and Oracle Database 10g XE databases. In Part
I of Chapters 4–6, Visual Basic.NET design tools and wizards are discussed and
analyzed in detail to show readers how to use them to easily and conveniently design
and build professional database programs with Visual Basic.NET.
For experienced college students or software programmers who already have
some knowledge of database programming, it is recommended to learn and under-
stand the contents of Part II of Chapters 4–6 as well as Chapters 7 and 8 since
the runtime data object method and some sophisticated database programming
techniques, such as joined-table query, nested stored procedures, and Oracle
Package, are discussed and illustrated with real examples. Also, ASP.NET Web
applications and ASP.NET Web services are discussed and analyzed with twenty-
four real database program examples for SQL Server 2005 and Oracle Database
10g XE.

1.5 HOW TO USE THE SOURCE CODE AND SAMPLE DATABASES


All source code for each real project developed in this book is available. All
projects are categorized by chapter in the folder DBProjects, which is available at
www.cambridge.org/9780521712354. (See Figure 1.2.)
You can copy or download the code onto your computer and run each project
as you like. To successfully run these projects on your computer, the following con-
ditions must be met:

 Visual Studio.NET 2005 or later must be installed on your computer.


Exploring the Variety of Random
Documents with Different Content
1.C. The Project Gutenberg Literary Archive Foundation (“the
Foundation” or PGLAF), owns a compilation copyright in the
collection of Project Gutenberg™ electronic works. Nearly all the
individual works in the collection are in the public domain in the
United States. If an individual work is unprotected by copyright law in
the United States and you are located in the United States, we do
not claim a right to prevent you from copying, distributing,
performing, displaying or creating derivative works based on the
work as long as all references to Project Gutenberg are removed. Of
course, we hope that you will support the Project Gutenberg™
mission of promoting free access to electronic works by freely
sharing Project Gutenberg™ works in compliance with the terms of
this agreement for keeping the Project Gutenberg™ name
associated with the work. You can easily comply with the terms of
this agreement by keeping this work in the same format with its
attached full Project Gutenberg™ License when you share it without
charge with others.

1.D. The copyright laws of the place where you are located also
govern what you can do with this work. Copyright laws in most
countries are in a constant state of change. If you are outside the
United States, check the laws of your country in addition to the terms
of this agreement before downloading, copying, displaying,
performing, distributing or creating derivative works based on this
work or any other Project Gutenberg™ work. The Foundation makes
no representations concerning the copyright status of any work in
any country other than the United States.

1.E. Unless you have removed all references to Project Gutenberg:

1.E.1. The following sentence, with active links to, or other


immediate access to, the full Project Gutenberg™ License must
appear prominently whenever any copy of a Project Gutenberg™
work (any work on which the phrase “Project Gutenberg” appears, or
with which the phrase “Project Gutenberg” is associated) is
accessed, displayed, performed, viewed, copied or distributed:
This eBook is for the use of anyone anywhere in the United
States and most other parts of the world at no cost and with
almost no restrictions whatsoever. You may copy it, give it away
or re-use it under the terms of the Project Gutenberg License
included with this eBook or online at www.gutenberg.org. If you
are not located in the United States, you will have to check the
laws of the country where you are located before using this
eBook.

1.E.2. If an individual Project Gutenberg™ electronic work is derived


from texts not protected by U.S. copyright law (does not contain a
notice indicating that it is posted with permission of the copyright
holder), the work can be copied and distributed to anyone in the
United States without paying any fees or charges. If you are
redistributing or providing access to a work with the phrase “Project
Gutenberg” associated with or appearing on the work, you must
comply either with the requirements of paragraphs 1.E.1 through
1.E.7 or obtain permission for the use of the work and the Project
Gutenberg™ trademark as set forth in paragraphs 1.E.8 or 1.E.9.

1.E.3. If an individual Project Gutenberg™ electronic work is posted


with the permission of the copyright holder, your use and distribution
must comply with both paragraphs 1.E.1 through 1.E.7 and any
additional terms imposed by the copyright holder. Additional terms
will be linked to the Project Gutenberg™ License for all works posted
with the permission of the copyright holder found at the beginning of
this work.

1.E.4. Do not unlink or detach or remove the full Project


Gutenberg™ License terms from this work, or any files containing a
part of this work or any other work associated with Project
Gutenberg™.

1.E.5. Do not copy, display, perform, distribute or redistribute this


electronic work, or any part of this electronic work, without
prominently displaying the sentence set forth in paragraph 1.E.1 with
active links or immediate access to the full terms of the Project
Gutenberg™ License.
1.E.6. You may convert to and distribute this work in any binary,
compressed, marked up, nonproprietary or proprietary form,
including any word processing or hypertext form. However, if you
provide access to or distribute copies of a Project Gutenberg™ work
in a format other than “Plain Vanilla ASCII” or other format used in
the official version posted on the official Project Gutenberg™ website
(www.gutenberg.org), you must, at no additional cost, fee or expense
to the user, provide a copy, a means of exporting a copy, or a means
of obtaining a copy upon request, of the work in its original “Plain
Vanilla ASCII” or other form. Any alternate format must include the
full Project Gutenberg™ License as specified in paragraph 1.E.1.

1.E.7. Do not charge a fee for access to, viewing, displaying,


performing, copying or distributing any Project Gutenberg™ works
unless you comply with paragraph 1.E.8 or 1.E.9.

1.E.8. You may charge a reasonable fee for copies of or providing


access to or distributing Project Gutenberg™ electronic works
provided that:

• You pay a royalty fee of 20% of the gross profits you derive from
the use of Project Gutenberg™ works calculated using the
method you already use to calculate your applicable taxes. The
fee is owed to the owner of the Project Gutenberg™ trademark,
but he has agreed to donate royalties under this paragraph to
the Project Gutenberg Literary Archive Foundation. Royalty
payments must be paid within 60 days following each date on
which you prepare (or are legally required to prepare) your
periodic tax returns. Royalty payments should be clearly marked
as such and sent to the Project Gutenberg Literary Archive
Foundation at the address specified in Section 4, “Information
about donations to the Project Gutenberg Literary Archive
Foundation.”

• You provide a full refund of any money paid by a user who


notifies you in writing (or by e-mail) within 30 days of receipt that
s/he does not agree to the terms of the full Project Gutenberg™
License. You must require such a user to return or destroy all
copies of the works possessed in a physical medium and
discontinue all use of and all access to other copies of Project
Gutenberg™ works.

• You provide, in accordance with paragraph 1.F.3, a full refund of


any money paid for a work or a replacement copy, if a defect in
the electronic work is discovered and reported to you within 90
days of receipt of the work.

• You comply with all other terms of this agreement for free
distribution of Project Gutenberg™ works.

1.E.9. If you wish to charge a fee or distribute a Project Gutenberg™


electronic work or group of works on different terms than are set
forth in this agreement, you must obtain permission in writing from
the Project Gutenberg Literary Archive Foundation, the manager of
the Project Gutenberg™ trademark. Contact the Foundation as set
forth in Section 3 below.

1.F.

1.F.1. Project Gutenberg volunteers and employees expend


considerable effort to identify, do copyright research on, transcribe
and proofread works not protected by U.S. copyright law in creating
the Project Gutenberg™ collection. Despite these efforts, Project
Gutenberg™ electronic works, and the medium on which they may
be stored, may contain “Defects,” such as, but not limited to,
incomplete, inaccurate or corrupt data, transcription errors, a
copyright or other intellectual property infringement, a defective or
damaged disk or other medium, a computer virus, or computer
codes that damage or cannot be read by your equipment.

1.F.2. LIMITED WARRANTY, DISCLAIMER OF DAMAGES - Except


for the “Right of Replacement or Refund” described in paragraph
1.F.3, the Project Gutenberg Literary Archive Foundation, the owner
of the Project Gutenberg™ trademark, and any other party
distributing a Project Gutenberg™ electronic work under this
agreement, disclaim all liability to you for damages, costs and
expenses, including legal fees. YOU AGREE THAT YOU HAVE NO
REMEDIES FOR NEGLIGENCE, STRICT LIABILITY, BREACH OF
WARRANTY OR BREACH OF CONTRACT EXCEPT THOSE
PROVIDED IN PARAGRAPH 1.F.3. YOU AGREE THAT THE
FOUNDATION, THE TRADEMARK OWNER, AND ANY
DISTRIBUTOR UNDER THIS AGREEMENT WILL NOT BE LIABLE
TO YOU FOR ACTUAL, DIRECT, INDIRECT, CONSEQUENTIAL,
PUNITIVE OR INCIDENTAL DAMAGES EVEN IF YOU GIVE
NOTICE OF THE POSSIBILITY OF SUCH DAMAGE.

1.F.3. LIMITED RIGHT OF REPLACEMENT OR REFUND - If you


discover a defect in this electronic work within 90 days of receiving it,
you can receive a refund of the money (if any) you paid for it by
sending a written explanation to the person you received the work
from. If you received the work on a physical medium, you must
return the medium with your written explanation. The person or entity
that provided you with the defective work may elect to provide a
replacement copy in lieu of a refund. If you received the work
electronically, the person or entity providing it to you may choose to
give you a second opportunity to receive the work electronically in
lieu of a refund. If the second copy is also defective, you may
demand a refund in writing without further opportunities to fix the
problem.

1.F.4. Except for the limited right of replacement or refund set forth in
paragraph 1.F.3, this work is provided to you ‘AS-IS’, WITH NO
OTHER WARRANTIES OF ANY KIND, EXPRESS OR IMPLIED,
INCLUDING BUT NOT LIMITED TO WARRANTIES OF
MERCHANTABILITY OR FITNESS FOR ANY PURPOSE.

1.F.5. Some states do not allow disclaimers of certain implied


warranties or the exclusion or limitation of certain types of damages.
If any disclaimer or limitation set forth in this agreement violates the
law of the state applicable to this agreement, the agreement shall be
interpreted to make the maximum disclaimer or limitation permitted
by the applicable state law. The invalidity or unenforceability of any
provision of this agreement shall not void the remaining provisions.
1.F.6. INDEMNITY - You agree to indemnify and hold the
Foundation, the trademark owner, any agent or employee of the
Foundation, anyone providing copies of Project Gutenberg™
electronic works in accordance with this agreement, and any
volunteers associated with the production, promotion and distribution
of Project Gutenberg™ electronic works, harmless from all liability,
costs and expenses, including legal fees, that arise directly or
indirectly from any of the following which you do or cause to occur:
(a) distribution of this or any Project Gutenberg™ work, (b)
alteration, modification, or additions or deletions to any Project
Gutenberg™ work, and (c) any Defect you cause.

Section 2. Information about the Mission of


Project Gutenberg™
Project Gutenberg™ is synonymous with the free distribution of
electronic works in formats readable by the widest variety of
computers including obsolete, old, middle-aged and new computers.
It exists because of the efforts of hundreds of volunteers and
donations from people in all walks of life.

Volunteers and financial support to provide volunteers with the


assistance they need are critical to reaching Project Gutenberg™’s
goals and ensuring that the Project Gutenberg™ collection will
remain freely available for generations to come. In 2001, the Project
Gutenberg Literary Archive Foundation was created to provide a
secure and permanent future for Project Gutenberg™ and future
generations. To learn more about the Project Gutenberg Literary
Archive Foundation and how your efforts and donations can help,
see Sections 3 and 4 and the Foundation information page at
www.gutenberg.org.

Section 3. Information about the Project


Gutenberg Literary Archive Foundation
The Project Gutenberg Literary Archive Foundation is a non-profit
501(c)(3) educational corporation organized under the laws of the
state of Mississippi and granted tax exempt status by the Internal
Revenue Service. The Foundation’s EIN or federal tax identification
number is 64-6221541. Contributions to the Project Gutenberg
Literary Archive Foundation are tax deductible to the full extent
permitted by U.S. federal laws and your state’s laws.

The Foundation’s business office is located at 809 North 1500 West,


Salt Lake City, UT 84116, (801) 596-1887. Email contact links and up
to date contact information can be found at the Foundation’s website
and official page at www.gutenberg.org/contact

Section 4. Information about Donations to


the Project Gutenberg Literary Archive
Foundation
Project Gutenberg™ depends upon and cannot survive without
widespread public support and donations to carry out its mission of
increasing the number of public domain and licensed works that can
be freely distributed in machine-readable form accessible by the
widest array of equipment including outdated equipment. Many small
donations ($1 to $5,000) are particularly important to maintaining tax
exempt status with the IRS.

The Foundation is committed to complying with the laws regulating


charities and charitable donations in all 50 states of the United
States. Compliance requirements are not uniform and it takes a
considerable effort, much paperwork and many fees to meet and
keep up with these requirements. We do not solicit donations in
locations where we have not received written confirmation of
compliance. To SEND DONATIONS or determine the status of
compliance for any particular state visit www.gutenberg.org/donate.

While we cannot and do not solicit contributions from states where


we have not met the solicitation requirements, we know of no
prohibition against accepting unsolicited donations from donors in
such states who approach us with offers to donate.

International donations are gratefully accepted, but we cannot make


any statements concerning tax treatment of donations received from
outside the United States. U.S. laws alone swamp our small staff.

Please check the Project Gutenberg web pages for current donation
methods and addresses. Donations are accepted in a number of
other ways including checks, online payments and credit card
donations. To donate, please visit: www.gutenberg.org/donate.

Section 5. General Information About Project


Gutenberg™ electronic works
Professor Michael S. Hart was the originator of the Project
Gutenberg™ concept of a library of electronic works that could be
freely shared with anyone. For forty years, he produced and
distributed Project Gutenberg™ eBooks with only a loose network of
volunteer support.

Project Gutenberg™ eBooks are often created from several printed


editions, all of which are confirmed as not protected by copyright in
the U.S. unless a copyright notice is included. Thus, we do not
necessarily keep eBooks in compliance with any particular paper
edition.

Most people start at our website which has the main PG search
facility: www.gutenberg.org.

This website includes information about Project Gutenberg™,


including how to make donations to the Project Gutenberg Literary
Archive Foundation, how to help produce our new eBooks, and how
to subscribe to our email newsletter to hear about new eBooks.
Welcome to our website – the ideal destination for book lovers and
knowledge seekers. With a mission to inspire endlessly, we offer a
vast collection of books, ranging from classic literary works to
specialized publications, self-development books, and children's
literature. Each book is a new journey of discovery, expanding
knowledge and enriching the soul of the reade

Our website is not just a platform for buying books, but a bridge
connecting readers to the timeless values of culture and wisdom. With
an elegant, user-friendly interface and an intelligent search system,
we are committed to providing a quick and convenient shopping
experience. Additionally, our special promotions and home delivery
services ensure that you save time and fully enjoy the joy of reading.

Let us accompany you on the journey of exploring knowledge and


personal growth!

ebooknice.com

You might also like