100% found this document useful (1 vote)
11 views

Instant ebooks textbook Practical Database Programming with Visual Basic NET 1st Edition Ying Bai download all chapters

The document provides information about the book 'Practical Database Programming with Visual Basic NET' by Ying Bai, which teaches readers to develop database programs using Visual Basic.NET and ADO.NET. It covers practical examples with popular database systems such as Microsoft Access, SQL Server, and Oracle, and includes additional resources for students and instructors. The book is aimed at students, programmers, and software engineers looking to enhance their database programming skills.

Uploaded by

raymeekayshe
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 (1 vote)
11 views

Instant ebooks textbook Practical Database Programming with Visual Basic NET 1st Edition Ying Bai download all chapters

The document provides information about the book 'Practical Database Programming with Visual Basic NET' by Ying Bai, which teaches readers to develop database programs using Visual Basic.NET and ADO.NET. It covers practical examples with popular database systems such as Microsoft Access, SQL Server, and Oracle, and includes additional resources for students and instructors. The book is aimed at students, programmers, and software engineers looking to enhance their database programming skills.

Uploaded by

raymeekayshe
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/ 67

Visit https://ebookfinal.

com to download the full version and


explore more ebooks

Practical Database Programming with Visual Basic


NET 1st Edition Ying Bai

_____ Click the link below to download _____


https://ebookfinal.com/download/practical-database-
programming-with-visual-basic-net-1st-edition-ying-bai/

Explore and download more ebooks at ebookfinal.com


Here are some suggested products you might be interested in.
Click the link to download

Practical Database Programming with Visual Basic NET 2nd


Edition Ying Bai

https://ebookfinal.com/download/practical-database-programming-with-
visual-basic-net-2nd-edition-ying-bai/

Clearly Visual Basic Programming with Microsoft Visual


Basic 2010 2nd Edition Diane Zak

https://ebookfinal.com/download/clearly-visual-basic-programming-with-
microsoft-visual-basic-2010-2nd-edition-diane-zak/

Essential ASP NET with Examples in Visual Basic NET 1st


Edition Fritz Onion

https://ebookfinal.com/download/essential-asp-net-with-examples-in-
visual-basic-net-1st-edition-fritz-onion/

Building Distributed Applications with Visual Basic NET


Dan Fox

https://ebookfinal.com/download/building-distributed-applications-
with-visual-basic-net-dan-fox/
Developing Web applications with Visual Basic NET and ASP
NET 1st Edition John Alexander

https://ebookfinal.com/download/developing-web-applications-with-
visual-basic-net-and-asp-net-1st-edition-john-alexander/

Microsoft Visual Basic NET Programming for the Absolute


Beginner 1st Edition Jonathan S. Harbour

https://ebookfinal.com/download/microsoft-visual-basic-net-
programming-for-the-absolute-beginner-1st-edition-jonathan-s-harbour/

Mastering Visual Basic NET 1st Edition Petroutsos

https://ebookfinal.com/download/mastering-visual-basic-net-1st-
edition-petroutsos/

Visual Basic NET Bible 1st Edition Bill Evjen

https://ebookfinal.com/download/visual-basic-net-bible-1st-edition-
bill-evjen/

Visual Basic and Visual Basic NET for Scientists and


Engineers 1st Edition Christopher Frenz (Auth.)

https://ebookfinal.com/download/visual-basic-and-visual-basic-net-for-
scientists-and-engineers-1st-edition-christopher-frenz-auth/
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
some distance from the shore. They attain to a length of from 2 to 4
feet. In the young, which have been described as Porthmeus, the
spines and finlets are connected by membrane with the rest of the
fin.
Lichia is an allied genus from the Mediterranean, tropical Atlantic,
and the coast of Chili; five species.
Temnodon.—Body oblong, compressed, covered with cycloid
scales of moderate size. Cleft of the mouth rather wide. Jaws with a
series of strong teeth; smaller ones on the vomer and the palatine
bones. The first dorsal with eight feeble spines connected by
membrane; finlets none. Lateral line not shielded. The second dorsal
and anal covered with very small scales.
Temnodon saltator, sometimes called “Skip-jack,” is spread over
nearly all the tropical and sub-tropical seas; it frequents principally
the coasts, but is also met with in the open sea. On the coasts of the
United States it is well known by the name of “Blue-fish,” being
highly esteemed as food, and furnishing excellent sport. It is one of
the most rapacious fishes, destroying an immense number of other
shore-fishes, and killing many more than they can devour. It grows to
a length of 5 feet, but the majority of those brought to market are not
half that length.
Trachynotus.—Body more or less elevated, compressed,
covered with very small scales. Cleft of the mouth rather small, with
short convex snout. Opercles entire. The first dorsal composed of free
spines in small number. No finlets. Teeth always small, and generally
lost with age.
Ten species are known from the tropical Atlantic and Indo-Pacific;
they rarely exceed a length of 20 inches. Some of the most common
marine fishes belong to this genus, for instance T. ovatus, which
ranges over the entire tropical zone.
Pammelas (perciformis) is allied to the preceding genus; from the
coast of New York.
Fig. 198.—Magnified scale of
Psettus argenteus.
Psettus.—Body much compressed and elevated; snout rather
short. One dorsal, entirely covered with scales, with seven or eight
spines; anal fin with three. Ventrals very small, rudimentary. Teeth
villiform; no teeth on the palate. Scales small, ctenoid.

Only three species are known; one, P. sebæ, from the west coast
of Africa, the two others from the Indo-Pacific. P. argenteus is a very
common fish, attaining to a length of about 10 inches.
Fig. 199.—Psettus argenteus.
Platax.—Body much compressed and elevated; snout very short.
One dorsal, with the spinous portion nearly entirely hidden, and
formed by from three to seven spines; anal with three. Ventrals well
developed, with one spine and five rays. Teeth setiform, with an outer
series of rather larger teeth, notched at the top; palate toothless.
Scales of moderate size or rather small.

These fishes are called “Sea-bats,” from the extraordinary length


of some portion of their dorsal and anal fins and of their ventrals.
These long lobes are generally of a deep black colour. In mature and
old individuals the fin-rays are much shorter than in the young, which
have been described as distinct species. There are probably not
more than seven species of “Sea-bats,” if so many, and they all
belong to the Indian Ocean and Western Pacific, where they are very
common.
Zanclus.—Body much compressed and elevated. One dorsal,
with seven spines, the third of which is very elongate. No teeth on the
palate. Scales minute, velvety.
One species (Z. cornutus), which is extremely common in the
Indo-Pacific. It is easily recognised by its snout, which is produced
like that of Chelmon, and by the broad black bands crossing the
yellow ground-colour. It attains to a length of eight inches, and
undergoes during growth similar changes as Acanthurus.
Anomalops.—Body oblong, covered with small, rough scales.
Snout very short, convex, with wide cleft of the mouth. Eyes very
large; below the eye, in a cavity of the infraorbital ring, there is a
glandular phosphorescent organ. Villiform teeth in the jaws and on the
palatine bones, none on the vomer. First dorsal fin short, with a few
feeble spines connected by membrane.
This genus, of which one species only is known (A. palpebratus),
represents the family of Horse-Mackerels in the depths of the sea;
but we do not know, at present, at what depth it lives. Only six
specimens have been obtained hitherto from the vicinity of
Amboyna, the Fidji, and Paumotu Islands; the largest was twelve
inches long.
Capros.—Body compressed and elevated. Mouth very protractile.
Scales rather small, spiny. First dorsal with nine spines, anal with
three. Ventral fins well developed. Minute teeth in the jaws and on the
vomer; none on the palatine bones.
The “Boar-fish” (C. aper) is common in the Mediterranean, and
not rarely found on the south coast of England.
Allied are Antigonia and Diretmus, known from a few individuals
obtained at Madeira and Barbadoes; they are probably fishes which
but rarely come to the surface.
Equula.—Body more or less compressed, elevated or oblong,
covered with small, deciduous, cycloid scales. Mouth very protractile.
Minute teeth in the jaws; none on the palate. One dorsal. Formula of
the fins: D. 8/1516, A. 3/14, V. 1/5. The lower præopercular margin
serrated.
Fig. 200.—Equula edentula.
Small species, abundant in the Indo-Pacific, disappearing on the
coasts of Japan and Australia. Some eighteen species have been
described.
Gazza is very similar to Equula, but armed with canine teeth in
the jaws.
Other genera referred to this family are Lactarius (L. delicatulus,
common, and eaten on the East Indian coasts), Seriolella, Paropsis,
and Platystethus.

Third Family—Cyttidæ.
Body elevated, compressed, covered with small scales, or with
bucklers, or naked; eye lateral. Teeth conical, small. No bony stay for
the præoperculum. Dorsal fin composed of two distinct portions.
Ventrals thoracic. No prominent papilla near the vent. Gill-opening
wide. More than ten abdominal and more than fourteen caudal
vertebræ.
The fishes of the “Dory” family are truly marine, and inhabit the
temperate zone of the Northern and Southern Hemispheres. Some
fossils from tertiary formations (one from Licata) belong to the genus
Zeus.
Zeus.—A series of bony plates runs along the base of the dorsal
and anal fins; another series on the abdomen. Three or four anal
spines.

“John Dorys” are found in the Mediterranean, on the eastern


temperate shores of the Atlantic, on the coasts of Japan and
Australia. Six species are known, all of which are highly esteemed
for the table. The English name given to one of the European
species (Zeus faber) seems to be partly a corruption of the Gascon
“Jau,” which signifies cock, “Dory” being derived from the French
Dorée, so that the entire name means Gilt-Cock. Indeed, in some
other localities of Southern Europe it bears the name of Gallo. The
same species occurs also on the coasts of South Australia and New
Zealand. The fishermen of Roman Catholic countries hold this fish in
special respect, as they recognise in a black round spot on its side
the mark left by the thumb of St. Peter when he took the piece of
money from its mouth.
Fig. 201.—Cyttus australis.
Cyttus.—Body covered with very small scales; no osseous
bucklers on any part of the body. Two anal spines; ventral fins
composed of one spine and six or eight rays.

Three species are known from Madeira, South Australia, and


New Zealand.

Fourth Family—Stromateidæ.
Body more or less oblong and compressed, covered with very
small scales; eye lateral. Dentition very feeble; œsophagus armed
with numerous horny, barbed processes. No bony stay for the
præoperculum. Dorsal fin single, long, without distinct spinous
division. More than ten abdominal and more than fourteen caudal
vertebræ.
This small family consists of strictly marine and partly pelagic
species referred to two genera, Stromateus and Centrolophus. The
former lacks ventral fins, at least in the adult stage, and is
represented by about ten species in almost all the tropical and
warmer seas. Centrolophus, hitherto known from two or three
European species only (of which one occasionally reaches the south
coast of England, where it is named “Black-fish”), has recently been
discovered on the coast of Peru, and has probably a much wider
range.

Fifth Family—Coryphænidæ.
Body compressed; eye lateral. Teeth small, conical, if present;
œsophagus smooth. No bony stay for the præoperculum. Dorsal fin
single, long, without distinct spinous division. More than ten
abdominal and more than fourteen caudal vertebræ.
All the members of this family have pelagic habits.
Representatives of it have been recognized in some fossil remains:
thus Goniognathus from the Isle of Sheppey, and the living genus
Mene (Gastrocnemus) at Monte Bolca.
Coryphæna.—Body compressed, rather elongate; adult
specimens with a high crest on the top of the head; cleft of the mouth
wide. A single dorsal extending from the occiput almost to the caudal,
which is deeply forked; no distinct dorsal and anal spines. The
ventrals are well developed, and can be received in a groove on the
abdomen. Scales very small. Rasp-like teeth in the jaws, on the vomer
and the palatine bones. Air-bladder absent.

Fig. 202.—Dolphin from the Atlantic.


Generally, though by misapplication of the name, called
“Dolphins.” About six species are known, each of which is probably
distributed over all the tropical and sub-tropical seas. Strictly pelagic
in their habits, they are most powerful swimmers; they congregate in
shoals, and pursue unceasingly the Flying-Fish, which try to escape
their enemies by long flying leaps. They attain to a length of six feet,
and are eagerly caught by sailors on account of their well-flavoured
flesh. The beauty of their, unfortunately fugitive, colours has ever
been a subject of admiration. As far as the colours are capable of
description, those of the common species (C. hippurus), which is
often seen in the Mediterranean, are silvery blue above, with
markings of a deeper azure, and reflections of pure gold, the lower
parts being lemon-yellow, marked with pale blue. The pectoral fins
are partly lead colour, partly yellow; the anal is yellow, the iris of the
eye golden. These iridescent colours change rapidly whilst the fish is
dying, as in the Mackerel. The form of the body, and especially of the
head, changes considerably with age. Very young specimens, from
one to six inches in length, are abundant in the open sea, and
frequently obtained in the tow-net. Their body is cylindrical, their
head as broad as high, and the eye relatively very large, much
longer than the snout. As the fish grows the body is more
compressed, and finally a high crest is developed on the head, and
the anterior part of the dorsal fin attains a height equal to that of the
body.
Brama.—Body compressed, and more or less elevated, covered
with rather small scales; cleft of the mouth very oblique, with the lower
jaw longest. Dorsal and anal fins many-rayed, the former with three or
four, the latter with two or three, spines; caudal deeply forked. Ventrals
thoracic, with one spine and five rays. The jaws with an outer series of
stronger teeth.
Pelagic fishes which, like the allied genus Taractes, range over
almost all the tropical and temperate seas.
Lampris.—Body compressed and elevated, covered with very
small deciduous scales; cleft of the mouth narrow. A single dorsal,
without a spinous portion. Ventrals composed of numerous rays. Teeth
none.
Fig. 203.—Lampris luna.
The “Sun-fish” (L. luna) is one of the most beautiful fishes of the
Atlantic. It attains to the large size of four feet in length, is bluish on
the back, with round silvery spots, which colour prevails on the lower
parts; the fins are of a deep scarlet. It is said to be excellent eating. It
is a pelagic fish, not rare about Madeira, but extending far
northwards in the Atlantic; it seems to be rarer in the Mediterranean.
All the specimens hitherto obtained were full-grown or nearly so. The
skeleton exhibits several peculiarities, viz. an extraordinary
development and dilatation of the humeral arch, and great strength
of the numerous and closely-set ribs.
Other Coryphænoid genera are Pteraclis, Schedophilus, Diana,
Ausonia, and Mene; all pelagic forms.

Sixth Family—Nomeidæ.
Body oblong, more or less compressed, covered with cycloid
scales of moderate size; eye lateral. No bony stay for the
præoperculum. Dorsal fin with a distinct spinous portion separated
from the soft; sometimes finlets; caudal forked. More than ten
abdominal, and more than fourteen caudal vertebræ.
Marine fishes; pelagic, at least when young.

Fig. 204.—Gastrochisma melampus.


Gastrochisma.—Cleft of the mouth wide. Finlets behind the
dorsal and anal fins. The ventral fins are exceedingly broad and long,
and can be completely concealed in a fold of the abdomen.

G. melampus, from the coast of New Zealand; scarce.


Nomeus.—Cleft of the mouth narrow. No finlets. The ventral fin is
long and broad, attached to the abdomen by a membrane, and can be
received in a fissure of the abdomen.

N. gronovii is a common pelagic fish in the Atlantic and Indian


Oceans; of small size.
Other genera belonging to this family are Psenes and Cubiceps.
Seventh Family—Scombridæ.
Body oblong, scarcely compressed, naked or covered with small
scales; eye lateral. Dentition well developed. No bony stay for the
præoperculum. Two dorsal fins; generally finlets. Ventrals thoracic,
with one spine and five rays. More than ten abdominal, and more
than fourteen caudal vertebræ.
The fishes of the “Mackerel” family are pelagic forms, abundant in
all the seas of the tropical and temperate zones. They are one of the
four families of fishes which are the most useful to man, the others
being the Gadoids, Clupeoids, and Salmonoids. They are fishes of
prey, and unceasingly active, their power of endurance in swimming
being equal to the rapidity of their motions. Their muscles receive a
greater supply of blood-vessels and nerves than in other fishes, and
are of a red colour, and more like those of birds or mammals. This
energy of muscular action causes the temperature of their blood to
be several degrees higher than in other fishes. They wander about in
shoals, spawn in the open sea, but periodically approach the shore,
probably in the pursuit of other fishes on which they feed.[43]
Scombridæ are well represented in tertiary formations: in the
Eocene schists of Glaris two extinct genera, Palimphyes and Isurus,
have been discovered. In Eocene and Miocene formations Scomber,
Thynnus, and Cybium are not uncommon.
Scomber.—The first dorsal continuous, with feeble spines; five or
six finlets behind the dorsal and anal. Scales very small, and equally
covering the whole body. Teeth small. Two short ridges on each side
of the caudal fin.

Mackerels proper are found in almost all temperate and tropical


seas, with the exception of the Atlantic shores of temperate South
America, where they have not been found hitherto. In Europe, and
probably also on the coast of England, three species occur: S.
scomber, the common Mackerel, which lacks an air-bladder; S.
pneumatophorus, a more southern species, with an air-bladder; and
S. colias, like the former, but with a somewhat different coloration,
and often called “Spanish” Mackerel. On the Cape of Good Hope, in
Japan, on the coast of California, in South Australia, and New
Zealand, Mackerels are abundant, which are either identical with, or
very closely allied to, the European species. On the coasts of the
United States the same species occur which tenant the western
parts of the Atlantic. Altogether seven species are known.

Fig. 205.—Thynnus thynnus.


Thynnus.—The first dorsal continuous, with the spines rather
feeble; from six to nine finlets behind the dorsal and anal. Scales of
the pectoral region crowded, forming a corslet. Teeth rather small. A
longitudinal keel on each side of the tail.
The best-known species of this genus is the “Tunny” (Thynnus
thynnus), abundant in the Mediterranean, and ranging to the south
coast of England and to Tasmania. It is one of the largest fishes of
the ocean, attaining to a length of 10 feet, and to a weight of more
than 1000 lbs. The fishery of the Tunny is systematically carried on
in the Mediterranean, and dates from the most remote antiquity. Its
salted preparation was esteemed by the Romans under the name of
Saltamentum sardicum. Its flesh is extensively eaten now, fresh as
well as preserved.
Thynnus pelamys, or the “Bonito,” is equally well known, and
ranges over all the tropical and temperate seas; it eagerly pursues
the Flying-fish, and affords welcome sport and food to the sailor. In
its form it resembles the Tunny, but is more slender and rarely above
three feet long.
Some of the other species are provided with very long pectoral
fins, and generally called by sailors “Albacore.” They are said to
grow to a length of six feet; Bennett in his “Whaling Voyage,” vol. ii.
p. 278, makes the following observations on Th. germo, from the
Pacific: “Ships when cruising slowly in the Pacific Ocean, are usually
attended by myriads of this fish for many successive months. A few
days’ rapid sailing is, nevertheless, sufficient to get rid of them,
however numerous they may be, for they seldom pay more than very
transient visits to vessels making a quick passage. When the ship is
sailing with a fresh breeze they swim pertinaciously by her side and
take the hook greedily, but should she be lying motionless or
becalmed they go off to some distance in search of prey, and cannot
be prevailed upon to take the most tempting bait the sailor can
devise. It is probably as a protection from their chief enemy, the
Sword-fish, that they seek the society of a ship. I am not aware that
the Shark is also their enemy; but they seemed to have an instinctive
dread of this large fish, and when it approached the ship, would
follow it in shoals, and annoy it in the same manner as the smaller
birds may be seen to annoy those of a larger and predaceous kind,
as the hawk or owl. They are very voracious and miscellaneous
feeders. Flying-fish, Calmars, and small shoal-fish are their most
natural food; though they do not refuse the animal offal from a ship.
Amongst the other food contained in their maw, we have found small
Ostracions, File-fish, Sucking-fish, Janthina shells, and pelagic
crabs; in one instance a small Bonita, and in a second a Dolphin
eight inches long, and a Paper-nautilus shell containing its sepia-
tenant. It was often amusing to watch an Albacore pursuing a Flying-
fish, and to mark the precision with which it swam beneath the feeble
æronaut, keeping him steadily in view, and preparing to seize him at
the moment of his descent. But this the Flying-fish would often elude
by instantaneously renewing his leap, and not unfrequently escape
by extreme agility.”
Pelamys.—The first dorsal continuous, with the spines rather
feeble; from seven to nine finlets behind the dorsal and anal. Scales of
the pectoral region forming a corslet. Teeth moderately strong. A
longitudinal keel on each side of the tail.
Five species are known, of which P. sarda is common in the
Atlantic and Mediterranean.
Auxis.—Differing from the preceding two genera in having very
small teeth in the jaws only, none on the palate.
Auxis rochei common in the Atlantic, Mediterranean, and Indian
Ocean.
Cybium.—The first dorsal continuous, with the spines rather
feeble; generally more than seven finlets behind the dorsal and anal.
Scales rudimentary or absent. Teeth strong; a longitudinal keel on
each side of the tail.
Twelve species from the tropical Atlantic and Indian Ocean;
frequenting more the coast-region than the open sea; attaining to a
length of four or five feet.
Elacate.—Body covered with very small scales; head depressed;
cleft of the mouth moderately wide; no keel on the tail. The spinous
dorsal is formed by eight small free spines; finlets none. Villiform teeth
in the jaws, on the vomer and the palatine bones.
Elacate nigra, a coast fish common in the warmer parts of the
Atlantic and the Indian Ocean.
Echeneis.—The spinous dorsal fin is modified into an adhesive
disk, occupying the upper side of the head and neck.
This genus is closely allied to the preceding, from which it differs
only by the transformation of the spinous dorsal fin into a sucking
organ. The spines being composed of two halves, each half is bent
down towards the right and the left, forming a support to a double
series of transverse lamellæ, rough on their edges, the whole disk
being of an oval shape and surrounded by a membranous fringe.
Each pair of lamellæ is formed out of one spine, which, as usual, is
supported at the base by an interneural spine. By means of this disk
the “Sucking-fishes” or “Suckers” are enabled to attach themselves
to any flat surface, a series of vacuums being created by the erection
of the usually recumbent lamellæ. The adhesion is so strong that the
fish can only be dislodged with difficulty, unless it is pushed forward
by a sliding motion. The Suckers attach themselves to sharks,
turtles, ships, or any other object which serves their purpose. They
cannot be regarded as parasites, inasmuch as they obtain their food
independently of their host. Being bad swimmers they allow
themselves to be carried about by other animals or vessels endowed
with a greater power of locomotion. They were as well known to the
ancients as they are to the modern navigators. Aristotle and Aelian
mention the Sucker under the name of φθεὶρ, or the Louse; “In the
sea between Cyrene and Egypt there is a fish about the Dolphin
(Delphinus), which they call the Louse; this becomes the fattest of all
fishes, because it partakes of the plentiful supply of food captured by
the Dolphin.” Later writers, then, repeat a story, the source of which
is unknown, viz. that the “Remora” is able to arrest vessels in their
course, a story which has been handed down to our own time. It
need not be stated that this is an invention, though it cannot be
denied that the attachment of one of the larger species may retard
the progress of a sailing vessel, especially when, as is sometimes
the case, several individuals accompany the same ship. An account
of a somewhat ingenious way of catching sleeping turtles by means
of a Sucking-fish held by a ring fastened round its tail, appears to
have originated rather from an experiment than from regular
practice.
Ten different species are known, of which Echeneis remora and
Echeneis naucrates are the most common. The former is short and
grows to a length of eight inches only, the latter is a slender fish, not
rarely found three feet long. The bulkiest is Echeneis scutata, which
attains to a length of two feet; individuals of that size weighing about
eight lbs.
The number of pairs of lamellæ varies in the various species,
from 12 to 27. The caudal fin of some of the species undergoes
great changes with age. In young specimens the middle portion of
the fin is produced into a long filiform lobe. This lobe becomes
gradually shorter, and the fin shows a rounded margin in individuals
of middle age. When the fish approaches the mature state, the upper
and lower lobes are produced, and the fin becomes subcrescentic or
forked.
[See Günther, “On the History of Echeneis.” Ann. and Mag. Nat.
Hist., 1860.]
Eighth Family.—Trachinidæ.
Body elongate, low, naked or covered with scales. Teeth small,
conical. No bony stay for the præoperculum. One or two dorsal fins,
the spinous portion being always shorter and much less developed
than the soft; the anal similarly developed as the soft dorsal; no
finlets. Ventrals with one spine and five rays. Gill-opening more or
less wide. Ten or more than ten abdominal, and more than fourteen
caudal vertebræ.
Carnivorous coast-fishes of small size, found in every quarter of
the globe, but scarcely represented in the Arctic zone (Trichodon);
on the other hand, they are rather numerous towards the Antarctic
circle. All are bad swimmers, generally moving along the bottom in
small depths. Only one genus (Bathydraco) is known from the deep-
sea.
A genus which shows the principal characters of this family
(Callipteryx), has been found in the tertiary deposits of Monte Bolca;
it is scaleless. A second genus, Trachinopsis, has been recently
described by Sauvage from the Upper Tertiary of Lorca in Spain; and
a third (Pseudoeleginus) from the Miocene of Licata.
This family may be subdivided into five groups:—
1. In the Uranoscopina the eyes are on the upper surface of the
head, directed upwards; the lateral line is continuous.
Uranoscopus.—Head large, broad, thick, partly covered with
bony plates; cleft of the mouth vertical. Scales very small. Two dorsal
fins, the first with from three to five spines; ventrals jugular; pectoral
rays branched. Villiform teeth in the jaws, on the vomer and palatine
bones; no canines. Generally a long filament below and before the
tongue. Gill-cover armed.
The position of the eyes on the upper surface of the head, which
these fishes have in common with many others, is well expressed by
the name Uranoscopus (Stare-gazer). Their eyes are very small, and
can be raised or depressed at the will of the fish. They are inactive
fishes, generally lying hidden at the bottom between stones,
watching for their prey. The delicate filament attached to the bottom
of their mouth, and playing in front of it in the current of water which
passes through the mouth, serves to lure small animals within reach
of the fish. Eleven species are known from the Indo-Pacific and
Atlantic, and one (U. scaber) from the Mediterranean; they attain
rarely a length of twelve inches.
Leptoscopus.—Form of the head as in Uranoscopus, but entirely
covered with a thin skin. Scales small, cycloid. One continuous dorsal;
ventrals jugular; pectoral rays branched. Villiform teeth in both jaws,
on the vomer and palatine bones; canines none. No oral filament. Gill-
cover unarmed.

Fig. 206.—Leptoscopus macropygus.


Leptoscopus macropygus, not rare on the coast of New Zealand.
Other genera of Stare-gazers are Agnus from the Atlantic coasts
of North America; Anema from the Indian Ocean and New Zealand;
and Kathetostoma from Australia and New Zealand.
2. In the Trachinina the eyes are more or less lateral; the lateral
line is continuous; and the intermaxillary without a larger tooth on its
posterior portion.
Trachinus.—Cleft of the mouth very oblique; eye lateral, but
directed upwards. Scales very small, cycloid. Two dorsal fins, the first
short, with six or seven spines; ventrals jugular; the lower pectoral
rays simple. Villiform teeth in the jaws, on the vomer and palatine
bones. Præorbital and præoperculum armed.

The “Weevers” are common fishes on the European coasts, and


but too well known to all fishermen; singularly enough they do not
extend across the Atlantic to the American coast, but reappear on
the coast of Chili! Wounds by their dorsal and opercular spines are
much dreaded, being extremely painful, and sometimes causing
violent inflammation of the wounded part. No special poison-organ
has been found in these fishes, but there is no doubt that the
mucous secretion in the vicinity of the spines has poisonous
properties. The dorsal spines as well as the opercular spine have a
deep double groove in which the poisonous fluid is lodged, and by
which it is inoculated in the punctured wound. On the British coasts
two species occur, T. draco, the Greater Weever, attaining to a
length of twelve inches, and T. vipera, the Lesser Weever, which
grows only to half that size.
Champsodon.—Body covered with minute granular scales; lateral
lines two, with numerous vertical branches. Cleft of the mouth wide,
oblique. Eye lateral, but directed upwards. Two dorsal fins; ventral fins
jugular; pectoral rays branched. Teeth in the jaws in a single series,
thin, long, of unequal size. Teeth on the vomer, none on the palate.
Gill-openings exceedingly wide. Præoperculum with a spine at the
angle and a fine serrature on the posterior margin.
Champsodon vorax is not uncommon at small depths off the
Philippine Islands, Admiralty Islands, and in the Arafura Sea.
Percis.—Body cylindrical, with small ctenoid scales; cleft of the
mouth slightly oblique; eye lateral, but directed upwards. Dorsal fins
more or less continuous, the spinous with four or five short stiff spines;
ventrals a little before the pectorals. Villiform teeth in the jaws, with the
addition of canines; teeth on the vomer, none on the palatines.
Opercles feebly armed.
Fifteen species; small, but prettily coloured shore-fishes of the
Indo-Pacific.
Sillago.—Body covered with rather small, ctenoid scales. Cleft of
the mouth small, with the upper jaw rather longer; eye lateral, large.
Two dorsals, the first with from nine to twelve spines; ventrals
thoracic. Villiform teeth in the jaws, and on the vomer, none on the
palatine bones. Operculum unarmed; præoperculum serrated. The
bones of the head with wide muciferous channels.
Eight species; small, plain-coloured shore-fishes, common in the
Indian Ocean to the coasts of Australia.
Bovichthys.—Head broad and thick; cleft of the mouth horizontal,
with the upper jaw rather longer; eye lateral, more or less directed
upwards. Scales none. Two separate dorsal fins, the first with eight
spines; ventrals jugular; the lower pectoral rays simple. Villiform teeth
in the jaws, on the vomer and the palatine bones; no canines.
Operculum with a strong spine; præorbital and præoperculum not
armed.
Three species are known from the South Pacific.

Fig. 207.—Head of Bovichthys variegatus,


from New Zealand.
Bathydraco.—Body elongate, sub-cylindrical; head depressed,
with the snout much elongate, spatulate; mouth wide, horizontal, with
the lower jaw prominent; eyes very large, lateral, close together.
Scales very small, imbedded in the skin. Lateral line wide, continuous.
One dorsal fin; ventrals jugular; the lower pectoral rays branched.
Teeth in the jaws in villiform bands; none on the vomer or the palatine
bones. Opercles unarmed; ten branchiostegals; the gill-membranes
free from the isthmus, and but slightly united in front. Air-bladder
none.

A deep-sea fish, found at a depth of 1260 fathoms in the


Antarctic Ocean (south of Heard Island).
Chænichthys.—Head very large, with the snout spatulate, and
with the cleft of the mouth very wide. Eye lateral. Scales none; lateral
line sometimes with granulated scutes. Two dorsals, the first with
seven spines; ventrals jugular. Jaws with rasp-like teeth; palate
toothless.
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!

ebookfinal.com

You might also like