100% found this document useful (7 votes)
32 views

Download ebooks file (Ebook) SQL Server Database Programming With Visual Basic.NET: Concepts, Designs and Implementations by Ying Bai ISBN 9781119608509, 1119608503 all chapters

The document provides information about various ebooks related to database programming with Visual Basic.NET and Java, authored by Ying Bai. It includes links to download these ebooks, details about their content, and ISBN numbers. Additionally, it outlines the structure and features of the book 'SQL Server Database Programming with Visual Basic.NET', including chapters on databases, ADO.NET, and LINQ.

Uploaded by

fraseyakesfr
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 (7 votes)
32 views

Download ebooks file (Ebook) SQL Server Database Programming With Visual Basic.NET: Concepts, Designs and Implementations by Ying Bai ISBN 9781119608509, 1119608503 all chapters

The document provides information about various ebooks related to database programming with Visual Basic.NET and Java, authored by Ying Bai. It includes links to download these ebooks, details about their content, and ISBN numbers. Additionally, it outlines the structure and features of the book 'SQL Server Database Programming with Visual Basic.NET', including chapters on databases, ADO.NET, and LINQ.

Uploaded by

fraseyakesfr
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/ 65

Download the Full Ebook and Access More Features - 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

OR CLICK HERE

DOWLOAD EBOOK

Download more ebook instantly today at https://ebooknice.com


Instant digital products (PDF, ePub, MOBI) ready for you
Download now and discover formats that fit your needs...

Start reading on any device today!

(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) 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 by Ying Bai ISBN
9780521712354, 9780521885188, 0521712351, 0521885183

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

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) 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) 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) Programming Microsoft SQL Server 2000 with Microsoft Visual Basic .NET by
Rick Dobson, Paul Cornell ISBN 9780735615359, 0735615357

https://ebooknice.com/product/programming-microsoft-sql-server-2000-with-
microsoft-visual-basic-net-975148

ebooknice.com

(Ebook) SQL Server Execution Plans. For SQL Server 2008 through to 2017 and Azure
SQL Database by Grant Fritchey ISBN 9781910035221, 191003522X

https://ebooknice.com/product/sql-server-execution-plans-for-sql-
server-2008-through-to-2017-and-azure-sql-database-11063662

ebooknice.com
SQL Server Database Programming
with Visual Basic.NET
IEEE Press
445 Hoes Lane
Piscataway, NJ 08854

IEEE Press Editorial Board


Ekram Hossain, Editor in Chief

Jón Atli Benediktsson David Alan Grier Elya B. Joffe


Xiaoou Li Peter Lian Andreas Molisch
Saeid Nahavandi Jeffrey Reed Diomidis Spinellis
Sarah Spurgeon Ahmet Murat Tekalp
SQL Server Database Programming
with Visual Basic.NET

Concepts, Designs and Implementations

Ying Bai
Department of Computer Science and Engineering
Johnson C. Smith University
Charlotte, North Carolina USA
Copyright © 2020 by The Institute of Electrical and Electronics Engineers, Inc. All rights reserved.

Published by John Wiley & Sons, Inc., Hoboken, New Jersey.


Published simultaneously in Canada.

No part of this publication may be reproduced, stored in a retrieval system, or transmitted in any form or by any means,
electronic, mechanical, photocopying, recording, scanning, or otherwise, except as permitted under Section 107 or 108
of the 1976 United States Copyright Act, without either the prior written permission of the Publisher, or authorization
through payment of the appropriate per-copy fee to the Copyright Clearance Center, Inc., 222 Rosewood Drive, Danvers,
MA 01923, (978) 750-8400, fax (978) 750-4470, or on the web at www.copyright.com. Requests to the Publisher for
permission should be addressed to the Permissions Department, John Wiley & Sons, Inc., 111 River Street, Hoboken, NJ
07030, (201) 748-6011, fax (201) 748-6008, or online at http://www.wiley.com/go/permission.

Limit of Liability/Disclaimer of Warranty: While the publisher and author have used their best efforts in preparing this
book, they make no representations or warranties with respect to the accuracy or completeness of the contents of this book
and specifically disclaim any implied warranties of merchantability or fitness for a particular purpose. No warranty may be
created or extended by sales representatives or written sales materials. The advice and strategies contained herein may not
be suitable for your situation. You should consult with a professional where appropriate. Neither the publisher nor author
shall be liable for any loss of profit or any other commercial damages, including but not limited to special, incidental,
consequential, or other damages.

For general information on our other products and services or for technical support, please contact our Customer Care
Department within the United States at (800) 762-2974, outside the United States at (317) 572-3993 or fax (317) 572-4002.

Wiley also publishes its books in a variety of electronic formats. Some content that appears in print may not be available in
electronic formats. For more information about Wiley products, visit our web site at www.wiley.com.

Library of Congress Cataloging-in-Publication Data


Names: Bai, Ying, 1956– author.
Title: SQL server database programming with visual basic.net : concepts,
designs and implementations / Ying Bai, Department of Computer Science
and Engineering, Johnson C. Smith University Charlotte, North Carolina.
Description: First edition. | Hoboken, NJ : John Wiley & Sons, Inc., [2020] |
Series: Wiley IEEE | Includes bibliographical references and index.
Identifiers: LCCN 2020016203 (print) | LCCN 2020016204 (ebook) | ISBN
9781119608509 (paperback) | ISBN 9781119608516 (adobe pdf) | ISBN
9781119608608 (epub)
Subjects: LCSH: SQL server. | Client/server computing. | Database
management. | Visual Basic (Computer program language)
Classification: LCC QA76.9.C55 S7525 2020 (print) | LCC QA76.9.C55
(ebook) | DDC 005.75/85–dc23
LC record available at https://lccn.loc.gov/2020016203
LC ebook record available at https://lccn.loc.gov/2020016204

Cover Design: Wiley


Cover Image: © Hoxton/Martin Barraud/Getty Images

Set in 9.5/12.5pt STIXTwoText by SPi Global, Pondicherry, India

Printed in the United States of America.

10 9 8 7 6 5 4 3 2 1
This book is dedicated to my wife, Yan Wang
and my daughter, Susan (Xue) Bai.
vii

Contents

About the Author xix


Preface xxi
Acknowledgment xxiii
About the Companion Website xxiv

Chapter 1 Introduction 1
1.1 ­Outstanding Features About This Book 2
1.2 ­This Book Is For 2
1.3 ­What This Book Covers 2
1.4 ­How This Book Is Organized and How to Use This Book 5
1.5 ­How to Use Source Codes and Sample Database 6
1.6 ­Instructors and Customers Supports 8

Chapter 2 Introduction to Databases 9


Ying Bai and Satish Bhalla
2.1 ­What Are Databases and Database Programs? 10
2.1.1 File Processing System 10
2.1.2 Integrated Databases 11
2.2 ­Develop a Database 12
2.3 ­Sample Database 13
2.3.1 Relational Data Model 13
2.3.2 Entity-Relationship Model (ER) 17
2.4 ­Identifying Keys 18
2.5 ­Define Relationships 18
2.6 ­ER Notation 22
2.7 ­Data Normalization 23
2.7.1 First Normal Form (1NF) 23
2.7.2 Second Normal Form (2NF) 24
2.7.3 Third Normal Form (3NF) 26
2.8 ­Database Components in Some Popular Databases 28
2.8.1 Microsoft Access Databases 28
2.8.2 SQL Server Databases 29
viii Contents

2.8.3 Oracle Databases 32


2.9 ­Create Microsoft SQL Server 2017 Express Sample Database 35
2.9.1 Create the LogIn Table 36
2.9.2 Create the Faculty Table 37
2.9.3 Create Other Tables 39
2.9.4 Create Relationships Among Tables 45
2.9.4.1 Create Relationship Between the LogIn and the Faculty Tables 46
2.9.4.2 Create Relationship Between the LogIn and the Student Tables 49
2.9.4.3 Create Relationship Between the Faculty and the Course Tables 50
2.9.4.4 Create Relationship Between the Student and the StudentCourse Tables 50
2.9.4.5 Create Relationship Between the Course and the StudentCourse Tables 51
2.9.5 Store Images to the SQL Server 2017 Express Database 53
2.10 ­Chapter Summary 61
Homework 63

Chapter 3 Introduction to ADO.NET 67


3.1 ­The ADO and ADO.NET 67
3.2 ­Overview of the ADO.NET 69
3.3 ­The Architecture of the ADO.NET 70
3.4 ­The Components of ADO.NET 71
3.4.1 The Data Provider 72
3.4.1.1 The ODBC Data Provider 73
3.4.1.2 The OLEDB Data Provider 73
3.4.1.3 The SQL Server Data Provider 74
3.4.1.4 The Oracle Data Provider 74
3.4.2 The Connection Class 74
3.4.2.1 The Open() Method of the Connection Class 77
3.4.2.2 The Close() Method of the Connection Class 77
3.4.2.3 The Dispose() Method of the Connection Class 78
3.4.3 The Command and the Parameter Classes 78
3.4.3.1 The Properties of the Command Class 79
3.4.3.2 The Constructors and Properties of the Parameter Class 79
3.4.3.3 Parameter Mapping 80
3.4.3.4 The Methods of the ParameterCollection Class 82
3.4.3.5 The Constructor of the Command Class 83
3.4.3.6 The Methods of the Command Class 84
3.4.4 The DataAdapter Class 87
3.4.4.1 The Constructor of the DataAdapter Class 87
3.4.4.2 The Properties of the DataAdapter Class 87
3.4.4.3 The Methods of the DataAdapter Class 88
3.4.4.4 The Events of the DataAdapter Class 88
3.4.5 The DataReader Class 90
3.4.6 The DataSet Component 92
Contents ix

3.4.6.1 The DataSet Constructor 94


3.4.6.2 The DataSet Properties 94
3.4.6.3 The DataSet Methods 94
3.4.6.4 The DataSet Events 94
3.4.7 The DataTable Component 97
3.4.7.1 The DataTable Constructor 98
3.4.7.2 The DataTable Properties 98
3.4.7.3 The DataTable Methods 99
3.4.7.4 The DataTable Events 100
3.4.8 ADO.NET Entity Framework 102
3.4.8.1 Advantages of Using the Entity Framework 6 104
3.4.8.2 The ADO.NET 4.3 Entity Data Model 106
3.4.8.3 Using Entity Framework 6 Entity Data Model Wizard 110
3.5 ­Chapter Summary 118
Homework 120

Chapter 4 Introduction to Language Integrated Query (LINQ) 123


4.1 ­Overview of Language Integrated Query 123
4.1.1 Some Special Interfaces Used in LINQ 124
4.1.1.1 The IEnumerable and IEnumerable(Of T) Interfaces 124
4.1.1.2 The IQueryable and IQueryable(Of T) Interfaces 125
4.1.2 Standard Query Operators 126
4.1.3 Deferred Standard Query Operators 127
4.1.4 Non-Deferred Standard Query Operators 131
4.2 ­Introduction to LINQ Query 135
4.3 ­The Architecture and Components of LINQ 137
4.3.1 Overview of LINQ to Objects 138
4.3.2 Overview of LINQ to DataSet 139
4.3.3 Overview of LINQ to SQL 139
4.3.4 Overview of LINQ to Entities 140
4.3.5 Overview of LINQ to XML 140
4.4 ­LINQ to Objects 141
4.4.1 LINQ and ArrayList 142
4.4.2 LINQ and Strings 143
4.4.2.1 Query a String to Determine the Number of Numeric Digits 144
4.4.2.2 Sort Lines of Structured Text By any Field in the Line 145
4.4.3 ­LINQ and File Directories 147
4.4.3.1 Query the Contents of Files in a Folder 148
4.4.4 LINQ and Reflection 150
4.5 ­LINQ to DataSet 152
4.5.1 Operations to DataSet Objects 152
4.5.1.1 Query Expression Syntax 153
4.5.1.2 Method-Based Query Syntax 154
x Contents

4.5.1.3 Query the Single Table 157


4.5.1.4 Query the Cross Tables 159
4.5.1.5 Query Typed DataSet 162
4.5.2 Operations to DataRow Objects Using the Extension Methods 165
4.5.3 Operations to DataTable Objects 169
4.6 ­LINQ to SQL 170
4.6.1 LINQ to SQL Entity Classes and DataContext Class 171
4.6.1.1 Add LINQ to Data Reference 171
4.6.1.2 Add LINQ To SQL Tools 171
4.6.2 LINQ to SQL Database Operations 175
4.6.2.1 Data Selection Query 175
4.6.2.2 Data Insertion Query 177
4.6.2.3 Data Updating Query 178
4.6.2.4 Data Deletion Query 179
4.6.3 LINQ to SQL Implementations 182
4.7 ­LINQ to Entities 182
4.7.1 The Object Services Component 183
4.7.2 The ObjectContext Component 183
4.7.3 ­The ObjectQuery Component 184
4.7.4 ­LINQ to Entities Flow of Execution 184
4.7.5 ­Implementation of LINQ to Entities 186
4.8 ­LINQ to XML 187
4.8.1 LINQ to XML Class Hierarchy 187
4.8.2 Manipulate XML Elements 188
4.8.2.1 Creating XML from Scratch 188
4.8.2.2 Insert XML 190
4.8.2.3 Update XML 191
4.8.2.4 Delete XML 192
4.8.3 Manipulate XML Attributes 192
4.8.3.1 Add XML Attributes 192
4.8.3.2 Get XML Attributes 193
4.8.3.3 Delete XML Attributes 193
4.8.4 Query XML with LINQ to XML 194
4.8.4.1 Standard Query Operators and XML 194
4.8.4.2 XML Query Extensions 195
4.8.4.3 Using Query Expressions with XML 196
4.8.4.4 Using XPath and XSLT with LINQ to XML 196
4.8.4.5 Mixing XML and Other Data Models 197
4.9 ­Visual Basic.NET Language Enhancement for LINQ 199
4.9.1 Lambda Expressions 199
4.9.2 Extension Methods 201
4.9.3 Implicitly Typed Local Variables 205
4.9.4 Query Expressions 206
4.10 ­Chapter Summary 208
Homework 209
Contents xi

Chapter 5 Data Selection Query with Visual Basic.NET 215


­ PART I Data Query with Visual Studio.NET Design Tools and Wizards 216
5.1 A Completed Sample Database Application Example 216
5.2 Visual Studio.NET Design Tools and Wizards 219
5.2.1 Data Components in the Toolbox Window 220
5.2.1.1 The DataSet 220
5.2.1.2 DataGridView 221
5.2.1.3 BindingSource 222
5.2.1.4 BindingNavigator 222
5.2.1.5 TableAdapter 223
5.2.1.6 TableAdapter Manager 223
5.2.2 Data Source Window 223
5.2.2.1 Add New Data Sources 224
5.2.2.2 Data Source Configuration Wizard 224
5.2.2.3 DataSet Designer 228
5.3 Query Data from SQL Server Database Using Design Tools and Wizards 231
5.3.1 Application User Interface 231
5.3.1.1 The LogIn Form 232
5.3.1.2 The Selection Form 232
5.3.1.3 The Faculty Form 232
5.3.1.4 The Course Form 234
5.3.1.5 The Student Form 234
5.4 Use Visual Studio Wizards and Design Tools to Query and Display Data 236
5.4.1 Query and Display Data using the DataGridView and Detail Controls 236
5.4.1.1 View the Entire Table 238
5.4.1.2 View Each Record or the Specified Columns with Detail View 241
5.4.2 Use DataSet Designer to Edit the Structure of the DataSet 243
5.4.3 Bind Data to the Associated Controls in LogIn Form 245
5.4.4 Develop Codes to Query Data Using the Fill() Method 249
5.4.5 Use Return a Single Value to Query Data for LogIn Form 251
5.4.6 Develop the Codes for the Selection Form 254
5.4.7 Query Data from the Faculty Table for the Faculty Form 256
5.4.8 Develop Codes to Query Data from the Faculty Table 258
5.4.8.1 Develop Codes to Query Data Using the TableAdapter Method 258
5.4.8.2 Develop Codes to Query Data Using the LINQ to DataSet Method 261
5.4.9 Query Data from the Course Table for the Course Form 262
5.4.9.1 Build the Course Queries Using the Query Builder 263
5.4.9.2 Bind Data Columns to the Associated Controls in the Course Form 265
5.4.9.3 Develop Codes to Query Data for the Course Form 267

­ PART II Data Query with Runtime Objects 271


5.5 Introduction to Runtime Objects 272
5.5.1 Procedure of Building a Data-Driven Application Using Runtime Object 274
5.6 Query Data from SQL Server Database Using Runtime Object 274
5.6.1 Access to SQL Server Database 274
xii Contents

5.6.2 Declare Global Variables and Runtime Objects 276


5.6.3 Query Data Using Runtime Objects for the LogIn Form 278
5.6.3.1 Connect to the Data Source with the Runtime Object 278
5.6.3.2 Coding for Method 1: Using the TableAdapter to Query Data 279
5.6.3.3 Coding for Method 2: Using the DataReader to Query Data 281
5.6.4 The Coding for the Selection Form 283
5.6.5 Query Data Using Runtime Objects for the Faculty Form 284
5.6.5.1 Using Three Query Methods to Retrieve Images from SQL Server Database 290
5.6.6 Query Data Using Runtime Objects for the Course Form 290
5.6.6.1 Retrieve Data from Multiple Tables Using Tables JOINS 293
5.6.7 Query Data Using Runtime Objects for the Student Form 301
5.6.7.1 Query Student Data Using Stored Procedures 302
5.6.7.2 Query Data Using Stored Procedures for Student Form 306
5.6.7.3 Query Data Using More Complicated Stored Procedures 315
5.7 Chapter Summary 320
Homework 321

Chapter 6 Data Inserting with Visual Basic.NET 327


­ PART I Insert Data with Visual Basic.NET Design Tools and Wizards 328
6.1 Insert Data Into a Database 328
6.1.1 Insert New Records into a Database Using the TableAdapter.Insert Method 329
6.1.2 Insert New Records into a Database Using the TableAdapter.Update Method 329
6.2 Insert Data into the SQL Server Database Using a Sample Project InsertWizard 330
6.2.1 Create InsertWizard Project Based on the SelectWizard Project 330
6.2.2 Application User Interfaces 331
6.2.3 Validate Data Before the Data Insertion 331
6.2.3.1 Visual Basic Collection and .NET Framework Collection Classes 331
6.2.3.2 Validate Data Using the Generic Collection 332
6.2.4 Initialization Coding Process for the Data Insertion 335
6.2.5 Build the Insert Query 336
6.2.5.1 Configure the TableAdapter and Build the Data Inserting Query 336
6.2.6 Develop Codes to Insert Data Using the TableAdapter.Insert Method 337
6.2.7 Develop Codes to Insert Data Using the TableAdapter.Update Method 341
6.2.8 Insert Data into the Database Using the Stored Procedures 345
6.2.8.1 Create the Stored Procedure Using the TableAdapter Query Configuration Wizard 346
6.2.8.2 Modify the Codes to Perform the Data Insertion Using the Stored Procedure 346

­ PART II Data Insertion with Runtime Objects 350


6.3 The General Run Time Objects Method 351
6.4 Insert Data into the SQL Server Database Using the Run Time Object Method 352
6.4.1 Insert Data into the Faculty Table for the SQL Server Database 353
6.4.1.1 Validate Data Before the Data Insertion 353
6.4.1.2 Insert Data into the Faculty Table 355
Contents xiii

6.4.1.3 Validate Data After the Data Insertion 357


6.5 Insert Data into the Database Using Stored Procedures 360
6.5.1 Insert Data into the SQL Server Database Using Stored Procedures 360
6.5.1.1 Develop Stored Procedures in SQL Server Database 361
6.5.1.2 Develop Codes to Call Stored Procedures to Insert Data into the Course Table   363
6.6 Insert Data into the Database Using the LINQ To SQL Method 368
6.6.1 Insert Data Into the SQL Server Database Using the LINQ to SQL Queries 369
6.7 Chapter Summary 369
Homework 370

Chapter 7 Data Updating and Deleting with Visual Basic.NET 377


­ PART I Data Updating and Deleting with Visual Studio.NET Design Tools and Wizards 378
7.1 Update or Delete Data Against Databases 378
7.1.1 Updating and Deleting Data from Related Tables in a DataSet 379
7.1.2 Update or Delete Data Against Database Using TableAdapter DBDirect
Methods - TableAdapter.Update and TableAdapter.Delete 379
7.1.3 Update or Delete Data Against Database Using TableAdapter.Update Method 380
7.2 Update and Delete Data For Microsoft SQL Server Database 381
7.2.1 Create a New Project Based on the InsertWizard Project 381
7.2.2 Application User Interfaces 382
7.2.3 Validate Data Before the Data Updating and Deleting 382
7.2.4 Build the Update and Delete Queries 382
7.2.4.1 Configure the TableAdapter and Build the Data Updating Query 383
7.2.4.2 Build the Data Deleting Query 384
7.2.5 Develop Codes to Update Data Using the TableAdapter DBDirect Method 385
7.2.5.1 Modifications of the Codes 385
7.2.5.2 Creations of the Codes 385
7.2.6 Develop Codes to Update Data Using the TableAdapter.Update Method 387
7.2.7 Develop Codes to Delete Data Using the TableAdapter DBDirect Method 388
7.2.8 Develop Codes to Delete Data Using the TableAdapter.Update Method 390
7.2.9 Validate the Data After the Data Updating and Deleting 391

­ PART II Data Updating and Deleting with Runtime Objects 395


7.3 The Run Time Objects Method 395
7.4 Update and Delete Data for SQL Server Database Using the Run Time Objects 396
7.4.1 Update Data Against the Faculty Table in the SQL Server Database 397
7.4.1.1 Develop Codes to Update the Faculty Data 397
7.4.1.2 Validate the Data Updating 399
7.4.2 Delete Data from the Faculty Table in the SQL Server Database 399
7.4.2.1 Develop Codes to Delete Data 399
7.4.2.2 Validate the Data Deleting 401
7.5 Update and Delete Data against SQL Server Database Using Stored Procedures 404
7.5.1 Modify an Existing Project to Create Our New Project 405
xiv Contents

7.5.2 Create the Codes to Update and Delete Data from the Course Table 405
7.5.2.1 Develop Two Stored Procedures in the SQL Server Database 407
7.5.2.2 Call the Stored Procedures to Perform the Data Updating and Deleting 409
7.5.3 Update and Delete Data against Databases Using the LINQ to SQL Query 412
7.5.3.1 Update and Delete Data Using LINQ to SQL Query for Student Table 413
7.5.3.2 Create a New Object of the DataContext Class for Student Form 414
7.5.3.3 Develop the Codes for the Select Button Click Event Procedure 415
7.5.3.4 Develop the Codes for the Insert Button Click Event Procedure 416
7.5.3.5 Develop the Codes for the Update Button Click Event Procedure 419
7.5.3.6 Develop the Codes for the Delete Button Click Event Procedure 419
7.5.3.7 Run the Project to Test Data Updating and Deleting Actions for Student Table 421
7.6 Chapter Summary 423
Homework 423

Chapter 8 Accessing Data in ASP.NET 429


8.1 ­What is .NET Framework? 430
8.2 ­What is ASP.NET? 431
8.2.1 ASP.NET Web Application File Structure 433
8.2.2 ASP.NET Execution Model 433
8.2.3 What is Really Happened When a Web Application is Executed? 434
8.2.4 The Requirements to Test and Run the Web Project 435
8.3 ­Develop ASP.NET Web Application to Select Data from SQL Server Databases 435
8.3.1 Create the User Interface – LogIn Form 436
8.3.2 Develop the Codes to Access and Select Data from the Database 438
8.3.3 Validate the Data in the Client Side 442
8.3.4 Create the Second User Interface – Selection Page 443
8.3.5 Develop the Codes to Open the Other Page 444
8.3.6 Modify the Codes in the LogIn Page to Transfer to the Selection Page 446
8.3.7 Create the Third User Interface – Faculty Page 447
8.3.8 Develop the Codes to Select the Desired Faculty Information 448
8.3.8.1 Develop the Codes for the Page_Load Event Procedure 449
8.3.8.2 Develop the Codes for the Select Button Click Event Procedure 450
8.3.8.3 Develop the Codes for Other Procedures 452
8.3.9 Create the Fourth User Interface – Course Page 454
8.3.9.1 The AutoPostBack Property of the List Box Control 457
8.3.10 Develop the Codes to Select the Desired Course Information 457
8.3.10.1 Coding for the Course Page Loading and Ending Event Procedures 458
8.3.10.2 Coding for the Select Button’s Click Event Procedure 459
8.3.10.3 Coding for the SelectedIndexChanged Event Procedure of the CourseList Box 461
8.3.10.4 Coding for Other User Defined Subroutine Procedures 463
8.4 ­Develop ASP.NET Web Application to Insert Data Into SQL Server Databases 465
8.4.1 Develop the Codes to Perform the Data Insertion Function 466
8.4.2 Develop the Codes for the Insert Button Click Event Procedure 466
Contents xv

8.4.3 Validate the Data Insertion 473


8.5 ­Develop Web Applications to Update and Delete Data in SQL Server Databases 473
8.5.1 Modify the Codes for the Faculty Page 474
8.5.2 Develop the Codes for the Update Button Click Event Procedure 475
8.5.3 Develop the Codes for the Delete Button Click Event Procedure 479
8.5.3.1 Relationships Between Five Tables in Our Sample Database 480
8.5.3.2 Data Deleting Sequence 481
8.5.3.3 Use the Cascade Deleting Option to Simplify the Data Deleting 481
8.5.3.4 Create the Stored Procedure to Perform the Data Deleting 483
8.5.3.5 Develop the Codes to Call the Stored Procedure to Perform the Data Deleting 486
8.6 ­Develop ASP.NET Web Applications with LINQ to SQL Query 489
8.6.1 Create a New Object of the DataContext Class 491
8.6.2 Develop the Codes for the Data Selection Query 492
8.6.3 Develop the Codes for the Data Insertion Query 493
8.6.4 Develop the Codes for the Data Updating and Deleting Queries 496
8.7 ­Chapter Summary 500
Homework 500

Chapter 9 ASP.NET Web Services 505


9.1 ­What Are Web Services and Their Components? 506
9.2 ­Procedures to Build a Web Service 508
9.2.1 The Structure of a Typical Web Service Project 508
9.2.2 The Real Considerations When Building a Web Service Project 509
9.2.3 Introduction to Windows Communication Foundation (WCF) 509
9.2.3.1 What is the WCF? 510
9.2.3.2 WCF Data Services 510
9.2.3.3 WCF Services 511
9.2.3.4 WCF Clients 511
9.2.3.5 WCF Hosting 512
9.2.3.6 WCF Visual Studio Templates 512
9.2.4 Procedures to Build an ASP.NET Web Service 513
9.3 ­Build ASP.NET Web Service Project to Access SQL Server Database 514
9.3.1 Files and Items Created in the New Web Service Project 515
9.3.2 A Feeling of the Hello World Web Service Project As it Runs 518
9.3.3 Modify the Default Namespace 520
9.3.4 Create a Base Class to Handle Error Checking for Our Web Service 522
9.3.5 Create a Customer Returned Class to Hold All Retrieved Data 522
9.3.6 Add Web Methods into Our Web Service Class 524
9.3.7 Develop the Codes for Web Methods to Perform the Web Services 524
9.3.7.1 Web Service Connection Strings 524
9.3.7.2 Modify the Existing HelloWorld Web Method 527
9.3.7.3 Develop the Codes to Perform the Database Queries 528
9.3.7.4 Develop the Codes for Subroutines Used in the Web Method 530
xvi Contents

9.3.8 Develop the Stored Procedure to Perform the Data Query 533
9.3.8.1 Develop the Stored Procedure WebSelectFacultySP 533
9.3.8.2 Add Another Web Method to Call the Stored Procedure 534
9.3.9 Use DataSet as the Returning Object for the Web Method 536
9.3.10 Build Windows-based Web Service Clients to Consume the Web Services 538
9.3.10.1 Create a Web Service Proxy Class 539
9.3.10.2 Develop the Graphic User Interface for the Windows-based Client Project 541
9.3.10.3 Develop the Code to Consume the Web Service 541
9.3.11 Build Web-based Web Service Clients to Consume the Web Service 548
9.3.11.1 Create a New Web Site Project and Add an Existing Web Page 548
9.3.11.2 Add a Web Service Reference and Modify the Web Form Window 549
9.3.11.3 Modify the Designer and Codes for the Related Event Procedures 550
9.3.12 Deploy the Completed Web Service to Production Servers 555
9.3.12.1 Publish the Desired Web Service 557
9.4 ­Build ASP.NET Web Service Project to Insert Data Into SQL Server Database 559
9.4.1 Create a New Web Service Project WebServiceSQLInsert 559
9.4.2 Develop Four Web Service Methods 560
9.4.2.1 Develop Codes for the First Web Method SetSQLInsertSP 561
9.4.2.2 Develop Codes for User Defined Functions and Subroutine Procedures 563
9.4.2.3 Develop the Second Web Method GetSQLInsert 565
9.4.2.4 Develop the Third Web Method SQLInsertDataSet 568
9.4.2.5 Develop the Fourth Web Method GetSQLInsertCourse 572
9.4.3 Build Windows-based Web Service Clients to Consume the Web Services 578
9.4.3.1 Create a Windows-Based Consume Project and a Web Service Proxy Class 578
9.4.3.2 Develop the Graphic User Interface for the Client Project 579
9.4.3.3 Develop the Code to Consume the Web Service 581
9.4.4 Build Web-based Web Service Clients to Consume the Web Services 594
9.4.4.1 Create a New Web Site Project and Add an Existing Web Page 594
9.4.4.2 Add a Web Service Reference and Modify the Web Form Window 595
9.4.4.3 Modify the Codes for the Related Event Procedures 596
9.5 ­Build ASP.NET Web Service to Update and Delete Data for SQL Server Database 606
9.5.1 Modify the Default Namespace and Add Database Connection String 607
9.5.2 Create Our Customer-Built Base and Returned Classes 608
9.5.3 Create a Web Method to Call Stored Procedure to Update Student Records 609
9.5.4 Create a Web Method to Call Stored Procedure to Delete Student Records 611
9.5.5 Develop Two Stored Procedures WebUpdateStudentSP and WebDeleteStudentSP 613
9.5.5.1 Develop the Stored Procedure WebUpdateStudentSP 613
9.5.5.2 Develop the Stored Procedure WebDeleteStudentSP 616
9.6 ­Build Windows-Based Web Service Clients to Consume the Web Services 618
9.6.1 Modify the Student Form Window 618
9.6.2 Add a New Web Reference to Our Client Project 619
9.6.3 Build the Codes to the Update Button Click Event Procedure 620
9.6.4 Build the Codes to the Delete Button Click Event Procedure 621
Contents xvii

9.7 ­ uild Web-Based Web Service Clients to Consume the Web Services 624
B
9.7.1 Create a New Web Site Application Project and Add an Existing Web Page 625
9.7.2 Add a Web Service Reference and Modify the Web Form Window 625
9.7.3 Modify the Codes Inside the Back Button Click Event Procedure 626
9.7.4 Add the Codes to the Update Button Click Event Procedure 626
9.7.5 Develop Codes for the Delete Button Click Event Procedure 628
9.8 ­Chapter Summary 631
Homework 632

Appendix A: Install and Configure SQL Server 2017 Express Database 637
Appendix B: Download and Install DevExpress .NET UI Controls 649
Appendix C: Download & Install FrontPage Server Extension for Windows 10 651
Appendix D: How to Use Sample Database 655
Index 657
xix

About the Author

Dr. YING BAI is a Professor in the Department of Computer Science and Engineering at Johnson C. Smith
University. His special interests include: artificial intelligent controls, soft-computing, mix-language pro-
gramming, fuzzy logic controls, robotic controls, robots calibrations, and database programming.
His industry experience includes positions as software and senior software engineer at companies such
as Motorola MMS, Schlumberger ATE Technology, Immix TeleCom, and Lam Research.
Since 2003, Dr. Bai has published fifteen (15) books with publishers such as Prentice Hall, CRC Press
LLC, Springer, Cambridge University Press, and Wiley IEEE Press. Two of them were translated into
other languages. The Russian translation of his first book titled Applications Interface Programming
Using Multiple Languages was published by Prentice Hall in 2005. The Chinese translation of his eigth
book titled Practical Database Programming with Visual C#.NET was published by Tsinghua University
Press in China in 2011. Most books are about software programming, serial port programming, fuzzy
logic controls in industrial applications, microcontroller controls and programming, as well as classical
and modern controls on microcontrollers.
During recent years, Dr. Bai has also published about sixty (60) academic research papers in IEEE
Trans. Journals and International conferences.
xxi

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 organiza-
tions based on the information collected and stored in the databases. A record company may decide to
market certain albums in selected regions based on the music preference of teenagers. Grocery stores
display more popular items at eye level and reorders are based on the inventories taken at regular inter-
vals. Other examples include patients’ records in hospitals, customers’ account information in banks,
book orders by the libraries, club memberships, auto part orders, and winter cloth stock by department
stores and many others.
In addition to database management systems, in order to effectively apply and implement databases in
real industrial or commercial systems, a good Graphic 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 be
selected to provide this GUI functionality. Unlike other programming languages, Visual Basic.NET is a
kind of language that has advantages such as being easy-to-learn and easy-to-be-understood with little
learning curves. Beginning of Visual Studio.NET 2005, Microsoft integrated a few programming lan-
guages such as Visual C++, Visual Basic, C# and Visual J# into a dynamic model called .NET Framework
that makes Internet and Web programming easy and simple, and any language integrated in this model
can be used to develop professional and efficient Web applications that can be used to communicate with
others via Internet. ADO.NET and ASP.NET are two important sub-models of .NET Framework. The
former provides all components, including the Data Providers, DataSet and DataTable, to access and
manipulate data against different databases. The latter provides support to develop Web applications and
Web services in ASP.NET environment to allow users to exchange information between clients and serv-
ers 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 and relational database such as
Microsoft SQL Server 2017. The book provides a detailed description about the practical considerations
and applications in database programming via Visual Basic.NET 2017 with authentic examples and
detailed explanations. More important, a new writing style is developed and implemented in this book,
combined with real examples, to provide readers with a clear picture as to how to handle the database
programming issues in Visual Basic.NET 2017 environment.
xxii Preface

The outstanding features of this book include, but are not limited to:
1) A novel writing style is adopted to try to attract students’ or beginning programmers’ interest in learn-
ing and developing practical database programs, and to avoid the headache caused by using huge
blocks of codes in the traditional database programming books.
2) Updated database programming tools and components are covered in the book, such as .NET
Framework 4.6, LINQ, ADO.NET 4.5 and ASP.NET 4.6, to enable readers to easily and quickly learn
and master advanced techniques in database programming and develop professional and practical
database applications.
3) A real completed sample database CSE_DEPT with Microsoft SQL Server 2017 is provided and used
for entire book. Step by step, a detailed illustration and description about how to design and build a
practical relational database are provided.
4) Covers both fundamental and advanced database-programming techniques to convenience both
beginning students and experienced programmers.
5) Various actual data providers are discussed and implemented in the sample projects, such as the SQL
Server and OleDb data providers. Instead of using the OleDb to access the SQL Server, the real SQL
Server data provider is utilized to connect to the Visual Basic.NET 2017 directly to perform data
operations.
6) All projects can be run in Microsoft Visual Studio.NET 2019 even they are developed and built with
Visual Studio.NET 2017.
7) Good textbook for college students, good reference book for programmers, software engineers, and
academic researchers.
I sincerely hope that this book can provide useful and practical help, and can guide all readers or users
who adopted this book to develop and build professional and practical database applications.

Ying Bai
xxiii

Acknowledgment

The first and most special thanks to my wife, Yan Wang, and I could not have finished this book without
her sincere encouragement and support.
My special thanks to Dr. Satish Bhalla who is the chapter contributor for this book. Dr. Bhalla is a spe-
cialist 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 the Editor, Mary Hatcher, who made this book available to the public. This book would
not have reached the market without her deep perspective and hard work. The same thanks are extended
to the editorial team of this book. Without their contributions, it would be impossible for this book to be
published.
These thanks should also be extended to the following book reviewers for their precious opinions to
this book:
●● Dr. Jiang (Linda) Xie, Professor, Department of Electrical and Computer Engineering, University of
North Carolina at Charlotte.
●● Dr. Dali Wang, Professor, Department of Physics and Computer Science, Christopher Newport University.
Last but not least, thanks should be forwarded to all people who have supported me to finish this book.
xxiv

About the Companion Website

This book is accompanied by a companion website:


www.wiley.com/go/bai/sql

The companion website consists of a student website and an instructor website, and contains:
●● Student Website
○○ DB Projects

○○ Images

○○ Sample Database

○○ VB Forms

●● Instructor Website
○○ DB Projects

○○ HW Solutions

○○ Images

○○ Sample Database

○○ Teaching Power Point Slides


1

Chapter 1

Introduction

For many years during my teaching database programming and Visual Basic.NET programming courses
in my college, I found that it is too difficult to find a good textbook for this topic so that I had to combine
a few different professional books together as references to teach these courses. Most of those books are
specially designed for programmers or software engineers, which cover a lot of programming strategies
and huge blocks of codes, which is a terrible headache to the college students or beginning programmers
who are new to the Visual Basic.NET and database programming. I have to prepare my class presenta-
tions and figure out all homeworks and exercises for my students. I dreamed that one day I could find a
good textbook that is suitable for college students or beginning programmers and help them to learn and
master the database programming with Visual Basic.NET easily and conveniently. Finally, I decided that
I needed to do something for this dream myself after a long time of waiting.
Another reason for me to have this idea is the job market. As you know, most industrial and commercial
companies in the US belong to database applications businesses such as manufacturers, banks, hospitals,
and retailers. The majority of them need professional people to develop and build database-related applica-
tions, but not database management and design systems. To enable our students to become good candidates
for those companies, we need to create a book like this one.
Unlike most database programming books in the current market, which discuss and present the data-
base programming techniques with huge blocks of programming codes from the first page to the last
page, this book tries to use a new writing style to show readers, especially college students, how to
develop professional and practical database programs in Visual Basic.NET 2017 by using Visual Studio.
NET Design Tools and Wizards related to ADO.NET 4.5, and to apply codes that are auto-generated by
various Wizards. By using this new style, the headache caused by using those huge blocks of program-
ming codes can be removed, instead, a simple and easy way to create database programs using the Design
Tools can be taken to attract students’ learning interest, and furthermore to enable students to build
professional and practical database programming in more efficient and interesting ways.
There are so many different database-programming books available on the market, but rarely can you
find a book like this one, which implemented a novel writing style to attract the students’ learning inter-
ests in this topic. To meet the needs of some experienced or advanced students or software engineers, the
book contains two programming methods: the interesting and easy-to-learn fundamental database pro-
gramming method – Visual Studio.NET Design Tools and Wizards, and advanced database programming

SQL Server Database Programming with Visual Basic.NET: Concepts, Designs and Implementations, First Edition. Ying Bai.
© 2020 The Institute of Electrical and Electronics Engineers, Inc. Published 2020 by John Wiley & Sons, Inc.
Companion website: www.wiley.com/go/bai/sql
2 Chapter 1 Introduction

method – runtime object method. In the second method, all database-related objects are created and
applied during or when your project is running by utilizing quite a few blocks of codes.

1.1 ­Outstanding Features About This Book

1) All programming projects can be run in Microsoft Visual Studio.NET 2019 even if all of them are
developed and built in Visual Studio.NET 2017.
2) A novel writing style is adopted to try to attract students’ or beginning programmers’ interests in
learning and developing practical database programs, and to avoid the headache caused by using
huge blocks of codes in the traditional database programming books.
3) Updated database programming tools and components are covered in the book, such as .NET
Framework 4.6, LINQ, ADO.NET 4.5 and ASP.NET 4.7, to enable readers to easily and quickly learn
and master advanced techniques in database programming and develop professional and practical
database applications.
4) A real completed sample database CSE_DEPT with Microsoft SQL Server 2018 database engine is
provided and used for the entire book. Step by step, a detailed illustration and description about how
to design and build a practical relational database are provided.
5) both fundamental and advanced database-programming techniques are covered to convenience both
beginning students and experienced programmers.
6) Various actual data providers are discussed and implemented in the sample projects, such as OleDb,
ODBC and SQL Server data providers. Instead of using the OleDb to access the SQL Server, the real
SQL Server data provider is utilized to connect to the Visual Basic.NET 2017 directly to perform data
operations.
7) The book provides homework and teaching materials, and these allow instructors to organize and pre-
pare their courses easily and rapidly, and enable students to understand what they learned better by
doing something themselves.
8) Good textbook for college students, good reference book for programmers, software engineers, and
academic researchers.

1.2 ­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 Microsoft
SQL Server 2018. Fundamental knowledge and understanding on Visual Basic.NET and Visual Studio.
NET IDE is assumed.

1.3 ­What This Book Covers

Nine chapters are included in this book. The contents of each chapter can be summarized as below:
●● Chapter 1 provides an introduction and summarization to the whole book.
1.3 ­What This Book Cover 3

●● Chapter 2 provides a detailed discussion and analysis of the structure and components about rela-
tional databases. Some key technologies in developing and designing database are also given and
discussed in this part. The procedure and components used to develop a practical relational database
with SQL Server 2018 is analyzed in detailed with some real data tables in our sample database
CSE_DEPT.
●● Chapter 3 provides an introduction to the ADO.NET, which includes the architectures, organizations
and components of the ADO.NET. Detailed discussions and descriptions are provided in this chapter
to give readers both fundamental and practical ideas and pictures in how to use components in ADO.
NET to develop professional data-driven applications. Two ADO.NET architectures are discussed to
enable users to follow the directions to design and build their preferred projects based on the different
organizations of the ADO.NET. Four popular data provides, such as OleDb, ODBC, SQL Server and
Oracle, are discussed in detail. The basic ideas and implementation examples of DataTable and DataSet
are also analyzed and described with some real coding examples.
●● Chapter 4 provides a detailed discussion and analysis about the Language-Integrated Query (LINQ),
which includes LINQ to Objects, LINQ to DataSet, LINQ to SQL, LINQ to Entities, and LINQ to XML.
An introduction to LINQ general programming guide is provided at the first part in this chapter. Some
popular interfaces widely used in LINQ, such as IEnumerable, IEnumerable(Of T), IQueryable and
IQueryable(Of T), and Standard Query Operators (SQO) including the deferred and non-deferred
SQO, are discussed in that part. An introduction to LINQ Query is given in the second section in this
chapter. Following this introduction, a detailed discussion and analysis about the LINQ queries that is
implemented for different data sources is provided in detail.
●● Starting from Chapter 5, the real database programming techniques with Visual Basic.NET such as
data selection queries are provided and discussed. Two parts are covered in this chapter: Part I
contains the detailed descriptions in how to develop professional data-driven applications with the
help of the Visual Studio.NET design tools and wizards with some real projects, and this part con-
tains a lot of hiding codes that are created by Visual Basic.NET automatically when using those
design tools and wizards. Therefore, the coding for this part is very simple and easy. Part II covers
an advanced technique, the runtime object method, in developing and building professional data-
driven applications. Detailed discussions and descriptions about how to build professional and
practical database applications using this runtime method are provided combined with four real
projects.
●● Chapter 6 provides detailed discussions and analyses about three popular data insertion methods with
Microsoft SQL Server 2018 database:
1) Using TableAdapter’s DBDirect methods TableAdapter.Insert() method
2) Using the TableAdapter’s Update() method to insert new records that have already been added into
the DataTable in the DataSet
3) Using the Command object’s ExecuteNonQuery() method.
This chapter is also divided into two parts: Methods 1 and 2 are related to Visual Studio.NET design
tools and wizards and therefore are covered in Part I. The third method is related to runtime object and
therefore it is covered in Part II. Three real projects are used to illustrate how to perform the data inser-
tion into the Microsoft SQL Server 2018 database. Some professional and practical data validation
methods are also discussed in this chapter to confirm the data insertion.
4 Chapter 1 Introduction

●● Chapter 7 provides discussions and analyses on three popular data updating and deleting methods
with four real project examples:
1) Using TableAdapter DBDirect. methods such as TableAdapter.Update() and TableAdapter.Delete() to
update and delete data directly again the databases.
2) Using TableAdapter.Update() method to update and execute the associated TableAdapter’s proper-
ties such as UpdateCommand or DeleteCommand to save changes made for the table in the DataSet
to the table in the database.
3) Using the run time object method to develop and execute the Command’s method ExecuteNonQuery()
to update or delete data again the database directly.
This chapter is also divided into two parts: Methods 1 and 2 are related to Visual Studio.NET design tools
and wizards and therefore are covered in Part I. The third method is related to runtime object and it is
covered in Part II. Four real projects are used to illustrate how to perform the data updating and deleting
against the database Microsoft SQL Server 2018. Some professional and practical data validation methods
are also discussed in this chapter to confirm the data updating and deleting actions. The key points in
performing the data updating and deleting actions against a relational database, such as the order to exe-
cute data updating and deleting between the parent and child tables, are also discussed and analyzed.
●● Chapter 8 provides introductions and discussions about the developments and implementations of
ASP.NET Web applications in Visual Basic.NET 2017 environment. At the beginning of Chapter 8, a
detailed and complete description about the ASP.NET and the .NET Framework is provided, and this
part is especially useful and important to students or programmers who do not have any knowledge or
background in the Web application developments and implementations. Following the introduction
section, a detailed discussion on how to install and configure the environment to develop the ASP.NET
Web applications is provided. Some essential tools such as the Web server, IIS and FrontPage Server
Extension 2000, as well as the installation process of these tools are introduced and discussed in detail.
Starting from section 8.3, the detailed development and building process of ASP.NET Web applications
to access databases are discussed with four real Web application projects. The popular database SQL
Server 2018 is utilized as the target databases for those development and building processes.
●● Chapter 9 provides introductions and discussions about the developments and implementations of
ASP.NET Web services in Visual Basic.NET 2017 environment. A detailed discussion and analysis
about the structure and components of the Web services is provided at the beginning of this chapter.
One of the most popular databases, Microsoft SQL Server 2018, is discussed and used for three kinds
of example Web service projects, which include:
1) WebServiceSQLSelect
2) WebServiceSQLInsert
3) WebServiceSQLUpdateDelete.
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. Totally nine (9) projects, including the Web service and the associated Web service
client projects, are developed in this chapter. All projects have been debugged and tested and can be run
in any Windows compatible operating systems such as Windows XP, Windows 7/8 and Windows 10.
1.4 ­How This Book Is Organized and How to Use This Boo 5

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 programming with Visual Basic.
NET and professional database programmers who has professional experience on this topic.
Chapters 2, 3, and 4 provide the fundamentals on database structures and components, ADO.NET
and LINQ components. Starting from chapter 5, which includes chapters 6 and 7, each chapter is
divided into two parts: fundamental part and advanced part. The data driven applications developed
with design tools and wizards provided by Visual Studio.NET, which can be considered as the funda-
mental part, have less coding-loads and therefore they are more suitable to students or programmers
who are new to the database programming with Visual Basic.NET. Part II contains the runtime object
method and it covers a lot of coding developments to perform the different data actions against the
database, and this method is more flexible and convenient to experienced programmers event a lot of
coding jobs is concerned.
Chapters 8 and 9 give a full discussion and analysis about the developments and implementations
of ASP.NET Web applications and Web services. These technologies are necessary to students and
programmers who want to develop and build Web applications and Web services to access and manip-
ulate data via Internet.
Based on the organization of this book we described above, this book can be used as two categories
such as Level I and Level II, which is shown in Figure 1.1.
For undergraduate college students or beginning software programmers, it is highly recommended to
learn and understand the contents of Chapters 2, 3, and 4, Part I of Chapters 5, 6, and 7 since those are
fundamental knowledge and techniques in database programming with Visual Basic.NET 2017. For
chapters 8 and 9, these areoptional to instructors and dependent on the time and schedule.

Level I

Chapter 2 Level II

Chapters 3 & 4 Chapters 3 & 4

Part I Part II
Chapter 5 Chapter 5

Part I Part II
Chapter 6 Chapter 6

Part I Part II
Chapter 7 Chapter 7
Optional

Chapter 8 Chapter 8

Chapter 9 Chapter 9

Figure 1.1 Two study levels in the book.


6 Chapter 1 Introduction

For experienced college students or software programmers who have already some knowledge and
techniques in database programming, it is recommended to learn and understand the contents of Part II
of Chapters 5 ~ 7 as well as Chapters 8 and 9 since the run-time data objects method and some sophisti-
cated database programming techniques such as joined-table query and nested stored procedures are
discussed and illustrated in those chapters with real examples. Also, the ASP.NET Web applications and
ASP.NET Web services are discussed and analyzed with many real database program examples for SQL
Server 2018 database.

1.5 ­How to Use Source Codes and Sample Database

All source codes in each project developed in this book are available, and all projects are categorized into
the associated chapters that are located at the folder DB Projects that is located at the site www.wiley.
com/go/bai/sql. You can copy or download those codes into your computer and run each project as you
like. To successfully run those projects, the following conditions must be met:
●● Visual Studio.NET 2017 or higher must be installed in your computer.
●● The database management system, Microsoft SQL Server 2018 Management Studio 18, must be
installed in your computer.
●● The sample database, CSE_DEPT.mdf, must be installed in your computer in the appropriate
folders.
●● To run projects developed in Chapters 8 and 9, in addition to conditions listed above, an Internet
Information Services (IIS) such as FrontPage Server Extension 2000 or 2002 must be installed in your
computer and it works as a pseudo server for those projects.
All related teaching and learning materials, including the sample databases, example projects, home-
work solutions, faculty and student images as well as sample Windows forms and Web pages, can be
found from the associated folders, Instructors or Students, located at the Wiley ftp site www.wiley.
com/go/bai/sql, as shown in Figure 1.2.
These materials are categorized and stored at different folders in two different sites based on the teach-
ing purpose (for instructors) and learning purpose (for students):
1) Sample Database Folder: Contains our sample database, CSE_DEPT.mdf (SQL Server 2018). Refer
to Appendix D to get details in how to use this database for your applications or sample projects.
2) DB Projects Folder: Contains all sample projects developed in the book. Projects are categorized and
stored at different Chapter subfolder based on the book chapter sequence. Readers can directly use the
codes and GUIs of those projects by downloading them from the DB Projects folder at the Wiley ftp
site.
3) Images Folder: Contains all sample faculty and student image files used in all sample projects in the
book. Readers can copy and paste those image files to their projects to use them.
4) VB Forms Folder: Contains all sampled Windows-based Forms and Web-based Pages developed and
implemented in all sample projects in the book. All Windows-based Forms are located at the Window
subfolder, and all Web-based Pages are located at the Web subfolder. Readers can use those Forms or
Pages by copying and pasting them into their real projects.
5) TeachingPPT Folder: Contains all MS-PPT teaching slides for each chapter.
1.5 ­How to Use Source Codes and Sample Databas 7

The Book Related Materials on the Web Sites

FOR INSTRUCTORS:

Instructor materials are available upon request from www.wiley.com/go/bai/sql/Instructors

DB Projects Images HWSolutions


Sample Database TeachingPPT

CSE_DEPT.mdf Chapter 1.ppt HW Solution.pdf


Chapter 5 Chapter 2.ppt Faculty
3 Projects
Chapter 3.ppt 13-Faculty
Chapter 6 Images
3 Projects Chapter 4.ppt

Chapter 7 Chapter 5.ppt


3 Projects Chapter 6.ppt Students
Chapter 8 Chapter 7.ppt 8-Student
1 Project Images
Chapter 8.ppt
Chapter 9 Chapter 9.ppt
6 Projects

FOR STUDENTS:

Learning materials are free to access via the site www.wiley.com/go/bai/sql/Students

DB Projects

Sample Database Images


VB Forms
Chapter 2
CSE_DEPT.mdf 1 Project
Window Faculty
Chapter 3
LogIn Form 1 Project 13-Faculty
Faculty Form Images
Chapter 4
Course Form 13 Projects
Student Form Chapter 5
Selection Form 4 Projects Students

Chapter 6 8-Student
Web Images
3 Projects
LogIn Page
Chapter 7
Faculty Page 4 Projects
Course Page
Student Page Chapter 8
4 Projects
Selection Page
Chapter 9
9 Projects

Figure 1.2 Book related materials on Web site.


Discovering Diverse Content Through
Random Scribd Documents
ST GILES, WEST WINDOW.
Page 105.
SOME MEMORANDA OF THE OLD
KIRK OF ST GILES.
The central portion or transept of St Giles’s Church, opening from
the south, formed a distinct place of worship, under the name of the
Old Church, and this seems to have been the first arranged for
Protestant worship after the Reformation. It was the scene of the
prelections of John Knox (who, it will be remembered, was the first
minister of the city under the reformed religion), until a month
before his death, when it appears that another portion of the
building—styled the Tolbooth Kirk—was fitted up for his use.

John Knox’s Pulpit.


It also happened to be in the Old Kirk that the celebrated riot of the
23rd of July 1637 took place, when, on the opening of the new
Episcopal service-book, Jenny Geddes, of worthy memory, threw her
cutty-stool at the dean who read it—the first weapon, and a
formidable one it was, employed in the great civil war.[72]
Jenny Geddes’s
Stool.
Jenny Geddes was an herbwoman—Scottice, a greenwife—at the
Tron Church, where, in former as well as in recent times, that class
of merchants kept their stalls. It seems that, in the midst of the
hubbub, Jenny, hearing the bishop call upon the dean to read the
collect of the day, cried out, with unintentional wit: ‘Deil colic the
wame o’ ye!’[73] and threw at the dean’s head the small stool on
which she sat; ‘a ticket of remembrance,’ as a Presbyterian annalist
merrily terms it, so well aimed that the clergyman only escaped it by
jouking;[74] that is, by [ducking or] suddenly bending his person.
Jenny, like the originators of many other insurrections, appears to
have afterwards repented of her exertions on this occasion. We learn
from the simple diarist, Andrew Nichol, that when Charles II. was
known, in June 1650, to have arrived in the north of Scotland,
amidst other rejoicings, ‘the pure [q.d. poor] kaill-wyves at the Trone
[Jenny Geddes, no doubt, among the number] war sae overjoyed,
that they sacrificed their standis and creellis, yea, the verie stoollis
they sat on, in ane fyre.’ What will give, however, a still more
unequivocal proof of the repentance of honest Jenny (after whom,
by the way, Burns named a favourite mare), is the conduct expressly
attributed to herself on the occasion of the king’s coronation in 1661
by the Mercurius Caledonius:
‘But among all our bontados and caprices,’ says that curious register
of events,[75] ‘that of the immortal Jenet Geddis, Princesse of the
Trone adventurers, was most pleasant; for she was not only content
to assemble all her Creels, Basquets, Creepies,[76] Furmes, and
other ingredients that composed the Shope of her Sallets, Radishes,
Turnips, Carrots, Spinage, Cabbage, with all other sorts of Pot
Merchandise that belongs to the garden, but even her Leather Chair
of State, where she used to dispense Justice to the rest of her
Langkale Vassals, were all very orderly burned; she herself
countenancing the action with a high-flown flourish and vermilion
majesty.’
The Scottish Society of Antiquaries nevertheless exhibit in their
museum a clasp-stool, for which there is good evidence that it was
the actual stool thrown by Mrs Geddes at the dean.
In the southern aisle of this church, the Regent Murray, three weeks
after his assassination at Linlithgow, February 14, 1569-70, was
interred: ‘his head placed south, contrair the ordour usit; the
sepulchre laid with hewin wark maist curiously, and on the head ane
plate of brass.’ John Knox preached a funeral-sermon over the
remains of his friend, and drew tears from the eyes of all present. In
the Tolbooth Church, immediately adjoining to the west, sat the
convention which chose the Earl of Lennox as his successor in the
regency. Murray’s monument was not inelegant for the time; and its
inscription, written by Buchanan, is remarkable for emphatic brevity.
Modern Monument to the Marquis
of Montrose (see p. 108).
This part of the church appears to have formerly been an open
lounge. French Paris, Queen Mary’s servant, in his confession
respecting the murder of Darnley, mentions that, during the
communings which took place before that deed was determined on,
he one day ‘took his mantle and sword, and went to walk
(promener) in the High Church.’ Probably, in consequence of the
veneration entertained for the memory of ‘the Good Regent,’ or else,
perhaps, from some simple motive of conveniency, the Earl of
Murray’s tomb was a place frequently assigned in bills for the
payment of the money. It also appears to have been the subject of a
similar jest to that respecting the tomb of Duke Humphrey. Robert
Sempill, in his Banishment of Poverty, a poem referring to the year
1680 or 1681, thus expresses himself:
‘Then I knew no way how to fen’;
My guts rumbled like a hurle-barrow;
I dined with saints and noblemen,
Even sweet Saint Giles and Earl of Murray.’

In the immediate neighbourhood of the Earl of Murray’s tomb, to the


east, is the sepulchre of the Marquis of Montrose, executed in 1650,
and here interred most sumptuously, June 1661, after the various
parts of his body had been dispersed for eleven years in different
directions, according to his sentence.[77]
THE PARLIAMENT CLOSE.
Ancient Churchyard—Booths attached to the High Church—
Goldsmiths—George Heriot—The Deid-Chack.
Previous to the seventeenth century, the ground now occupied by
the Parliament House, and the buildings adjacent to the south and
west, was the churchyard of St Giles’s, from the south side of which
edifice it extended down a steep declivity to the Cowgate. This might
formerly be considered the metropolitan cemetery of Scotland; as,
together with the internal space of the church, it contained the
ashes of many noble and remarkable personages, John Knox
amongst the number. After the Reformation, when Queen Mary
conferred the gardens of the Greyfriars upon the town, the
churchyard of St Giles’s ceased to be much used as a burying-
ground; and that extensive and more appropriate place of sepulture
succeeded to this in being made the Westminster Abbey of Scotland.
The west side of the cemetery of St Giles’s was bounded by the
house of the provost of the church, who, in 1469, granted part of
the same to the citizens for the augmentation of the burying-ground.
From the charter accompanying the grant, it appears that the
provost’s house then also contained the public school of Edinburgh.
In the lower part of the churchyard[78] there was a small place of
worship denominated the Chapel of Holyrood. Walter Chapman, the
first printer in Edinburgh, in 1528 endowed an altar in this chapel
with his tenement in the Cowgate; and, by the tenor of the charter, I
am enabled to point out very nearly the residence of this interesting
person, who, besides being a printer, was a respectable merchant in
Edinburgh, and, it would appear, a very pious man. The tenement is
thus described: ‘All and haill this tenement of land, back and foir,
with houses, biggings, yards, and well[79] thereof, lying in the
Cowgate of Edinburgh, on the south side thereof, near the said
chapel, betwixt the lands of James Lamb on the east, and the lands
of John Aber on the west, the arable lands called Wairam’s Croft on
the south, and the said street on the north part.’

BOOTHS.
The precincts of St Giles’s being now secularised, the church itself
was, in 1628, degraded by numerous wooden booths being stuck up
around it. Yet, to show that some reverence was still paid to the
sanctity of the place, the Town-council decreed that no tradesmen
should be admitted to these shops except bookbinders, mortmakers
(watchmakers), jewellers, and goldsmiths. Bookbinders must here be
meant to signify booksellers, the latter term not being then known in
Scotland. Of mortmakers there could not be many, for watches were
imported from Germany till about the conclusion of the seventeenth
century. The goldsmiths were a much more numerous tribe than
either of their companions; for at that time there prevailed in
Scotland, amongst the aristocracy, a sort of rude magnificence and
taste for show extremely favourable to these tradesmen.
Old St Giles’s.
In 1632, the present great hall of the Parliament House was founded
upon the site of the houses formerly occupied by the ministers of St
Giles’s. It was finished in 1639, at an expense of £11,630 sterling,
and devoted to the use of parliament.
It does not appear to have been till after the Restoration that the
Parliament Close was formed, by the erection of a line of private
buildings, forming a square with the church. These houses, standing
on a declivity, were higher on one side than the other; one is said to
have been fifteen stories altogether in height. All, however, were
burned down in a great fire which happened in 1700, after which
buildings of twelve stories in height were substituted.[80]
Among the noble inhabitants of the Parliament Close at an early
period, the noble family of Wemyss were not the least considerable.
At the time of Porteous’s affair, when Francis, the fifth earl, was a
boy, his sisters persuaded him to act the part of Captain Porteous in
a sort of drama which they got up in imitation of that strange scene.
The foolish romps actually went the length of tucking up their
brother, the heir of the family, by the neck, over a door; and their
sports had well-nigh ended in a real tragedy, for the helpless
representative of Porteous was black in the face before they saw the
necessity of cutting him down.[81]
The small booths around St Giles’s continued, till 1817, to deform
the outward appearance of the church. Long before their
destruction, the booksellers at least had found the space of six or
seven feet too small for the accommodation of their fast-increasing
wares, and removed to larger shops in the elegant tenements of the
square. One of the largest of the booths, adjacent to the south side
of the New or High Church, and having a second story, was
occupied, during a great part of the last century, by Messrs Kerr and
Dempster, goldsmiths. The first of these gentlemen had been
member of parliament for the city, and was the last citizen who ever
held that office [in the Scottish parliament]. Such was the humility of
people’s wishes in those days respecting their houses, that this
respectable person actually lived, and had a great number of
children, in the small space of the flat over the shop and the cellar
under it, which was lighted by a grating in the pavement of the
square. The subterraneous part of his house was chiefly devoted to
the purposes of a nursery, and proved so insalubrious that all his
children died successively at a particular age, with the exception of
his son Robert, who, being born much more weakly than the rest,
had the good luck to be sent to the country to be nursed, and
afterwards grew up to be the author of a work entitled The Life of
Robert Bruce, and the editor of a large collection of voyages and
travels.

GOLDSMITHS.
The goldsmiths of those days were considered a superior class of
tradesmen; they appeared in public with scarlet cloak, cocked hat,
and cane, as men of some consideration. Yet in their shops every
one of them would have been found working with his own hands at
some light labour, in a little recess near the window, generally in a
very plain dress, but ready to come forth at a moment’s notice to
serve a customer. Perhaps, down to 1780, there was not a goldsmith
in Edinburgh who did not condescend to manual labour.
As the whole trade was collected in the Parliament Close, this was of
course the place to which country couples resorted, during the last
century, in order to make the purchase of silver tea-spoons, which
always preceded their nuptials. It was then as customary a thing in
the country for the intending bridegroom to take a journey, a few
weeks before his marriage, to the Parliament Close, in order to buy
the silver spoons, as it was for the bride to have all her clothes and
stock of bed-furniture inspected by a committee of matrons upon the
wedding eve. And this important transaction occasioned two
journeys: one, in order to select the spoons, and prescribe the
initials which were to be marked upon them; the other, to receive
and pay for them. It must be understood that the goldsmiths of
Edinburgh then kept scarcely any goods on hand in their shops, and
that the smallest article had to be bespoken from them some time
before it was wanted. A goldsmith, who entered as an apprentice
about the beginning of the reign of George III., informed me that
they were beginning only at that time to keep a few trifling articles
on hand. Previously another old custom had been abolished. It had
been usual, upon both the occasions above mentioned, for the
goldsmith to adjourn with his customer to John’s Coffee-house,[82]
or to the Baijen-hole,[83] and to receive the order or the payment, in
a comfortable manner, over a dram and a caup of small ale; which
were upon the first occasion paid for by the customer, and upon the
second by the trader; and the goldsmith then was perhaps let into
the whole secret counsels of the rustic, including a history of his
courtship—in return for which he would take pains to amuse his
customer with a sketch of the city news. In time, as the views and
capitals of the Parliament Close goldsmiths became extended, all
these pleasant customs were abandoned.[84]
HERIOT’S HOSPITAL
from Greyfriars’ Churchyard.
Page 113.
GEORGE HERIOT.
The shop and workshop of George Heriot existed in this
neighbourhood till 1809, when the extension of the Advocates’
Library occasioned the destruction of some interesting old closes to
the west of St Giles’s Kirk, and altered all the features of this part of
the town. There was a line of three small shops, with wooden
superstructures above them, extending between the door of the Old
Tolbooth and that of the Laigh Council-house, which occupied the
site of the present lobby of the Signet Library. A narrow passage led
between these shops and the west end of St Giles’s; and George
Heriot’s shop, being in the centre of the three, was situated exactly
opposite to the south window of the Little Kirk. The back windows
looked into an alley behind, called Beith’s or Bess Wynd. In
confirmation of this tradition, George Heriot’s name was discovered
upon the architrave of the door, being carved in the stone, and
apparently having served as his sign. Besides this curious memorial,
the booth was also found to contain his forge and bellows, with a
hollow stone, fitted with a stone cover or lid, which had been used
as a receptacle for and a means of extinguishing the living embers of
the furnace, upon closing the shop at night. All these curiosities
were bought by the late Mr E. Robertson of the Commercial Bank,
who had been educated in Heriot’s Hospital, and by him presented
to the governors, who ordered them to be carefully deposited and
preserved in the house, where they now remain. George Heriot’s
shop was only about seven feet square! Yet his master, King James,
is said to have sometimes visited him and been treated by him here.
There is a story that one day, when the goldsmith visited His Majesty
at Holyrood, he found him sitting beside a fire, which, being
composed of perfumed wood, cast an agreeable smell through the
room. Upon George Heriot remarking its pleasantness, the king told
him that it was quite as costly as it was fine. Heriot said that if His
Majesty would come and pay him a visit at his shop, he would show
him a still more costly fire.
‘Indeed!’ said the king; ‘and I will.’ He accordingly paid the goldsmith
a visit, but was surprised to find only an ordinary fire. ‘Is this, then,
your fine fire?’ said he.
‘Wait a little,’ said George, ‘till I get my fuel.’ So saying, he took from
his bureau a bond for two thousand pounds which he had lent to the
king, and laying it in the fire, added: ‘Now, whether is your Majesty’s
fire or mine most expensive?’
‘Yours most certainly, Master Heriot,’ said the king.
Adjacent to George Heriot’s shop, and contiguous to the Laigh
Council-house, there was a tavern, in which a great deal of small
legal business used to be transacted in bygone times. Peter
Williamson, an original and singular person, who had long been in
North America, and therefore designated himself ‘from the other
world,’ kept this house for many years.[85] It served also as a sort of
vestry to the Tolbooth Church, and was the place where the
magistrates took what was called the Deid-chack—that is, a
refreshment or dinner, of which those dignitaries always partook
after having attended an execution. The Deid-chack is now abjured,
like many other of those fashions which formerly rendered the office
of a magistrate so much more comfortable than it now is.[86]
The various kirks which compose St Giles’s had all different
characters in former times. The High Kirk had a sort of dignified
aristocratic character, approaching somewhat to prelacy, and was
frequented only by sound church-and-state men, who did not care
so much for the sermon as for the gratification of sitting in the same
place with His Majesty’s Lords of Council and Session and the
magistrates of Edinburgh, and who desired to be thought men of
sufficient liberality and taste to appreciate the prelections of Blair.
The Old Kirk, in the centre of the whole, was frequented by people
who wished to have a sermon of good divinity, about three-quarters
of an hour long, and who did not care for the darkness and
dreariness of their temple. The Tolbooth Kirk was the peculiar resort
of a set of rigid Calvinists from the Lawnmarket and the head of the
Bow, termed the Towbuith-Whigs, who loved nothing but extempore
evangelical sermons, and would have considered it sufficient to bring
the house down about their ears if the precentor had ceased, for
one verse, the old hillside fashion of reciting the lines of the psalm
before singing them. Dr Webster, of convivial memory, was long one
of the clergymen of this church, and deservedly admired as a pulpit
orator; though his social habits often ran nigh to scandalise his
devout and self-denying congregation.
The inhabitants and shopkeepers of the Parliament Square were in
former times very sociable and friendly as neighbours, and formed
themselves into a sort of society, which was long known by the
name of The Parliament-Close Council. Of this association there were
from fifty to a hundred members, who met once or twice a year at a
dinner, when they usually spent the evening, as the newspaper
phrase goes, ‘in the utmost harmony.’ The whim of this club
consisted in each person assuming a titular dignity at the dinner, and
being so called all the year after by his fellow-members. One was
Lord Provost of Edinburgh, another was Dean of Guild, some were
bailies, others deacons, and a great proportion state-officers. Sir
William Forbes, who, with the kindness of heart which characterised
him, condescended to hold a place in this assemblage of mummers,
was for a long time Member for the City.
Previous to the institution of the police-court, a bailie of Edinburgh
used to sit, every Monday, at that part of the Outer Parliament
House where the statue of Lord Melville now stands, to hear and
decide upon small causes—such as prosecutions for scandals and
defamation, or cases of quarrels among the vulgar and the
infamous. This judicature, commonly called the Dirt Court, was
chiefly resorted to by washerwomen from Canonmills and the
drunken ale-wives of the Canongate. A list of Dirt-Court processes
used always to be hung up on a board every Monday morning at one
of the pillars in the piazza at the outside of the Parliament Square;
and that part of the piazza, being the lounge of two or three low
pettifoggers who managed such pleas, was popularly called the
Scoundrels’ Walk. Early on Monday, it was usual to see one or two
threadbare personages, with prodigiously clean linen, bustling about
with an air of importance, and occasionally accosted by viragoes
with long-eared caps flying behind their heads. These were the
agents of the Dirt Court, undergoing conference with their clients.
There was something lofty and august about the Parliament Close,
which we shall scarcely ever see revived in any modern part of the
town; so dark and majestic were the buildings all round, and so
finely did the whole harmonise with the ancient cathedral which
formed one of its sides! Even the echoes of the Parliament Square
had something grand in them. Such, perhaps, were the feelings of
William Julius Mickle when he wrote a poem on passing through the
Parliament Close of Edinburgh at midnight,[87] of which the following
is one of the best passages:

‘In the pale air sublime,


St Giles’s column rears its ancient head,
Whose builders many a century ago
Were mouldered into dust. Now, O my soul,
Be filled with sacred awe—I tread
Above our brave forgotten ancestors. Here lie
Those who in ancient days the kingdom ruled,
The counsellors and favourites of kings,
High lords and courtly dames, and valiant chiefs,
Mingling their dust with those of lowest rank
And basest deeds, and now unknown as they.’
A SUGGESTION OF THE NORTH LOCH AND ST
CUTHBERT’S
from Allan Ramsay’s Garden.
Page 117.
MEMORIALS OF THE NOR’ LOCH.
He who now sees the wide hollow space between the Old and New
Towns, occupied by beautiful gardens, having their continuity only
somewhat curiously broken up by a transverse earthen mound and a
line of railway, must be at a loss to realise the idea of the same
space presenting in former times a lake, which was regarded as a
portion of the physical defences of the city. Yet many, in common
with myself, must remember the by no means distant time when the
remains of this sheet of water, consisting of a few pools, served as
excellent sliding and skating ground in winter, while their neglected
grass-green precincts too frequently formed an arena whereon the
high and mighty quarrels of Old and New Town cowlies[88]
[etymology of the word unknown] were brought to a lapidarian
arbitration.
The lake, it after all appears, was artificial, being fed by springs
under the Castle Rock, and retained by a dam at the foot of
Halkerston’s Wynd;[89] which dam was a passable way from the city
to the fields on the north. Bower, the continuator of Fordun, speaks
of a tournament held on the ground, ubi nunc est lacus, in 1396, by
order of the queen [of Robert III.], at which her eldest son, Prince
David, then in his twentieth year, presided. At the beginning of the
sixteenth century a ford upon the North Loch is mentioned.
Archbishop Beatoun escaped across that ford in 1517, when flying
from the unlucky street-skirmish called Cleanse the Causeway. In
those early times the town corporation kept ducks and swans upon
the loch for ornament’s sake, and various acts occur in their register
for preserving those birds. An act, passed in council between the
years 1589 and 1594, ordained ‘a boll of oats to be bought for
feeding the swans in the North Loch;’ and a person was unlawed at
the same time for shooting a swan in the said loch, and obliged to
find another in its place. The lake seems to have been a favourite
scene for boating. Various houses in the neighbourhood had
servitudes of the use of a boat upon it; and these, in later times,
used to be employed to no little purpose in smuggling whisky into
the town.
The North Loch was the place in which our pious ancestors used to
dip and drown offenders against morality, especially of the female
sex. The Reformers, therefore, conceived that they had not only
done a very proper, but also a very witty thing, when they threw into
this lake, in 1558, the statue of St Giles, which formerly adorned
their High Church, and which they had contrived to abstract.
It was also the frequent scene of suicide, and on this point one or
two droll anecdotes are related. A man was deliberately proceeding
to drown himself in the North Loch, when a crowd of the
townspeople rushed down to the water-side, venting cries of horror
and alarm at the spectacle, yet without actually venturing into the
water to prevent him from accomplishing the rash act. Hearing the
tumult, the father of the late Lord Henderland threw up his window
in James’s Court, and leaning out, cried down the brae to the
people: ‘What’s all the noise about? Can’t ye e’en let the honest man
gang to the de’il his ain gate?’ Whereupon the honest man quietly
walked out of the loch, to the no small amusement of his lately
appalled neighbours. It is also said that a poor woman, having
resolved to put an end to her existence, waded a considerable way
into the water, designing to take the fatal plunge when she should
reach a place where the lake was sufficiently deep. Before she could
satisfy herself on that point, her hoop caught the water, and lifted
her off her feet. At the same time the wind caught her figure, and
blew her, whether she would or not, into the centre of the pool, as if
she had been sailing upon an inverted tub. She now became
alarmed, screamed for help, and waved her arms distractedly; all of
which signs brought a crowd to the shore she had just left, who
were unable, however, to render her any assistance, before she had
landed on the other side—fairly cured, it appeared, of all desire of
quitting the uneasy coil of mortal life.
THE PARLIAMENT HOUSE.
Old Arrangements of the House—Justice in Bygone Times—
Court of Session Garland—Parliament House Worthies.
The Parliament House, a spacious hall with an oaken arched roof,
finished in 1639 for the meetings of the Estates or native parliament,
and used for that purpose till the Union, has since then, as is well
known, served exclusively as a material portion of the suite of
buildings required for the supreme civil judicatory—the Court of
Session. This hall, usually styled the Outer House, is now a nearly
empty space, but it was in a very different state within the
recollection of aged practitioners. So lately as 1779, it retained the
divisions, furnishings, and other features which it had borne in the
days when we had a national legislature—excepting only that the
portraits of sovereigns which then adorned the walls had been
removed by the Earl of Mar, to whom Queen Anne had given them
as a present when the Union was accomplished.
The divisions and furniture, it may be remarked, were understood to
be precisely those which had been used for the Court of Session
from an early time; but it appears that such changes were made
when the parliament was to sit as left the room one free vacant
space. The southern portion, separated from the rest by a screen,
accommodated the Court of Session. The northern portion,
comprising a sub-section used for the Sheriff-court, was chiefly a
kind of lobby of irregular form, surrounded by little booths, which
were occupied as taverns, booksellers’ shops, and toy-shops, all of
very flimsy materials.[90] These krames, or boxes, seem to have
been established at an early period, the idea being no doubt taken
from the former condition of Westminster Hall. John Spottiswoode of
Spottiswoode, who, in 1718, published the Forms of Process before
the Court of Session, mentions that there were ‘two keepers of the
session-house, who had small salaries to do all the menial offices in
the house, and that no small part of their annual perquisites came
from the kramers in the outer hall.’

JUSTICE IN BYGONE TIMES.


The memories which have been preserved of the administration of
justice by the Court of Session in its earlier days are not such as to
increase our love for past times.[91] This court is described by
Buchanan as extremely arbitrary, and by a nearly contemporary
historian (Johnston) as infamous for its dishonesty. An advocate or
barrister is spoken of by the latter writer as taking money from his
clients, and dividing it among the judges for their votes. At this time
we find the chancellor (Lord Fyvie) superintending the lawsuits of a
friend, and writing to him the way and manner in which he proposed
they should be conducted. But the strongest evidence of the
corruption of ‘the lords’ is afforded by an act of 1579, prohibiting
them ‘be thame selffis or be their wiffis or servandes, to tak in ony
time cuming, buddis, bribes, gudes, or geir, fra quhatever persone
or persons presentlie havand, or that heirefter sall happyne to have,
any actionis or caussis pursewit befoir thame, aither fra the
persewer or defender,’ under pain of confiscation. Had not bribery
been common amongst the judges, such an act as this could never
have been passed.
In the curious history of the family of Somerville there is a very
remarkable anecdote illustrative of the course of justice at that
period. Lord Somerville and his kinsman, Somerville of
Cambusnethan, had long carried on a litigation. The former was at
length advised to use certain means for the advancement of his
cause with the Regent Morton, it being then customary for the
sovereign to preside in the court. Accordingly, having one evening
caused his agents to prepare all the required papers, he went next
morning to the palace, and being admitted to the regent, informed
him of the cause, and entreated him to order it to be called that
forenoon. He then took out his purse, as if to give a few pieces to
the pages or servants, and slipping it down upon the table, hurriedly
left the presence-chamber. The earl cried several times after him:
‘My lord, you have left your purse;’ but he had no wish to stop. At
length, when he was at the outer porch, a servant overtook him with
a request that he would go back to breakfast with the regent. He did
so, was kindly treated, and soon after was taken by Morton in his
coach to the court-room in the city. ‘Cambusnethan, by accident, as
the coach passed, was standing at Niddry’s Wynd head, and having
inquired who was in it with the regent, he was answered: “None but
Lord Somerville and Lord Boyd;” upon which he struck his breast,
and said: “This day my cause is lost!” and indeed it proved so.’ By
twelve o’clock that day, Lord Somerville had gained a cause which
had been hanging in suspense for years.
In those days both civil and criminal procedure was conducted in
much the same spirit as a suit at war. When a great noble was to be
tried for some monstrous murder or treason, he appeared at the bar
with as many of his retainers, and as many of his friends and their
retainers, as he could muster, and justice only had its course if the
government chanced to be the strongest, which often was not the
case. It was considered dishonourable not to countenance a friend in
troubles of this kind, however black might be his moral guilt. The
trial of Bothwell for the assassination of Darnley is a noted example
of a criminal outbraving his judges and jury. Relationship, friendly
connection, solicitation of friends, and direct bribes were admitted
and recognised influences to which the civil judge was expected to
give way. If a difficulty were found in inducing a judge to vote
against his conscience, he might at least perhaps be induced by
some of those considerations to absent himself, so as to allow the
case to go in the desired way. The story of the abduction of Gibson
of Durie by Christie’s Will, and his immurement in a Border tower for
some weeks, that his voice might be absent in the decision of a case
—as given in the Border Minstrelsy by Scott—is only incorrect in
some particulars. (As the real case is reported in Pitcairn’s Criminal
Trials, it appears that, in September 1601, Gibson was carried off
from the neighbourhood of St Andrews by George Meldrum, younger
of Dumbreck, and hastily transported to the castle of Harbottle in
Northumberland, and kept there for eight days.) But, after all,
Scotland was not singular among European nations in these
respects. In Molière’s Misanthrope, produced in 1666, we find the
good-natured Philinte coolly remonstrating with Alceste on his
unreasonable resolution to let his lawsuit depend only on right and
equity.
‘Qui voulez-vous donc, qui pour vous sollicite?’ says Philinte. ‘Aucun
juge par vous ne sera visité?’
‘Je ne remuerai point,’ returns the misanthrope.
Philinte. Votre partie est forte, et peut par sa cabale entrainer....
Alceste. Il n’importe....
Philinte. Quel homme!... On se riroit de vous, Alceste, si on vous
entendoit parler de la façon. (People would laugh at you if they
heard you talk in this manner.)
It is a general tradition in Scotland that the English judges whom
Cromwell sent down to administer the law in Scotland, for the first
time made the people acquainted with impartiality of judgment. It is
added that, after the Restoration, when native lords were again put
upon the bench, some one, in presence of the President Gilmour,
lauding the late English judges for the equity of their proceedings,
his lordship angrily remarked: ‘De’il thank them; a wheen kinless
loons!’ That is, no thanks to them; a set of fellows without relations
in the country, and who, consequently, had no one to please by their
decisions.
After the Restoration there was no longer direct bribing, but other
abuses still flourished. The judges were tampered with by private
solicitation. Decisions went in favour of the man of most personal or
family influence. The following anecdote of the reign of Charles II.
rests on excellent authority: ‘A Scotch gentleman having entreated
the Earl of Rochester to speak to the Duke of Lauderdale upon the
account of a business that seemed to be supported by a clear and
undoubted right, his lordship very obligingly promised to do his
utmost endeavours to engage the duke to stand his friend in a
concern so just and reasonable as his was; and accordingly, having
conferred with his grace about the matter, the duke made him this
very odd return, that though he questioned not the right of the
gentleman he recommended to him, yet he could not promise him a
helping hand, and far less success in business, if he knew not first
the man, whom perhaps his lordship had some reason to conceal;
“because,” said he to the earl, “if your lordship were as well
acquainted with the customs of Scotland as I am, you had
undoubtedly known this among others—Show me the man, and I’ll
show you the law;” giving him to understand that the law in
Scotland could protect no man if either his purse were empty or his
adversaries great men, or supported by great ones.’[92]
One peculiar means of favouring a particular party was then in the
power of the presiding judge: he could call a cause when he
pleased. Thus he would watch till one or more judges who took the
opposite view to his own were out of the way—either in attendance
on other duties or from illness—and then calling the cause, would
decide it according to his predilection. Even the first President
Dalrymple, afterwards Viscount Stair, one of the most eminent men
whom the Scottish law-courts have ever produced, condescended to
favour a party in this way. An act enjoining the calling of causes
according to their place in a regular roll was passed in the reign of
Charles II.; but the practice was not enforced till the days of
President Forbes, sixty years later. We have a remarkable illustration
of the partiality of the bench in a circumstance which took place
about the time of the Revolution. During the pleadings in a case
between Mr Pitilloch, an advocate, and Mr Aytoun of Inchdairnie, the
former applied the term briber to Lord Harcarse, a judge seated at
the moment on the bench, and who was father-in-law to the
opposite party. The man was imprisoned for contempt; but this is
not the point. Not long after, in this same cause, Lord Harcarse went
down to the bar in his gown, and pleaded for his son-in-law Aytoun!
About that period a curious indirect means of influencing the judges
began to be notorious. Each lord had a dependant or favourite,
generally some young relative, practising in the court, through whom
it was understood that he could be prepossessed with a favourable
view of any cause. This functionary was called a Peat or Pate, from a
circumstance thus related in Wilkes’s North Briton: ‘One of the
former judges of the Court of Session, of the first character,
knowledge, and application to business, had a son at the bar whose
name was Patrick; and when the suitors came about, soliciting his
favour, his question was: “Have you consulted Pat?” If the answer
was affirmative, the usual reply of his lordship was: “I’ll inquire of
Pat about it; I’ll take care of your cause; go home and mind your
business.” The judge in that case was even as good as his word, for
while his brother-judges were robing, he would tell them what pains
his son had taken, and what trouble he had put himself to, by his
directions, in order to find out the real circumstances of the dispute;
and as no one on the bench would be so unmannerly as to question
the veracity of the son or the judgment of the father, the decree
always went according to the information of Pat. At the present era,
in case a judge has no son at the bar, his nearest relation (and he is
sure to have one there) officiates in that station. But, as it frequently
happens, if there are Pats employed on each side, the judges differ,
and the greatest interest—that is, the longest purse—is sure to carry
it.’
I bring the subject to a conclusion by a quotation from the Court of
Session Garland: ‘Even so far down as 1737 traces of the ancient evil
may be found. Thus, in some very curious letters which passed
between William Foulis, Esq. of Woodhall, and his agent, Thomas
Gibson of Durie, there is evidence that private influence could even
then be resorted to. The agent writes to his client, in reference to a
pending lawsuit (23rd November 1735): “I have spoken to Strachan
and several of the lords, who are all surprised Sir F[rancis Kinloch]
should stand that plea. By Lord St Clair’s advice, Mrs Kinloch is to
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