• Tidak ada hasil yang ditemukan

Contents at a Glance

N/A
N/A
Protected

Academic year: 2024

Membagikan "Contents at a Glance"

Copied!
15
0
0

Teks penuh

(1)

Contents at a Glance

About the Author

. . . xix

About the Technical Reviewers

. . . xxi

Acknowledgments

. . . xxiii

Introduction

. . . xxv

■ CHAPTER 1 Data Sources and the Web

. . . 1

■ CHAPTER 2 Introducing Relational Databases

. . . 27

■ CHAPTER 3 Displaying Data on a Page

. . . 77

■ CHAPTER 4 Database Access in Code

. . . 115

■ CHAPTER 5 DataReader and DataSet

. . . 155

■ CHAPTER 6 Inline and List Binding

. . . 189

■ CHAPTER 7 Table Binding

. . . 247

■ CHAPTER 8 Writing to the Database

. . . 297

■ CHAPTER 9 The GridView Family

. . . 367

■ CHAPTER 10 Stored Procedures

. . . 415

■ CHAPTER 11 Modifying the Database Structure

. . . 459

■ CHAPTER 12 Useful Techniques

. . . 497

■ CHAPTER 13 Application Design and Implementation

. . . 547

■ APPENDIX A Installation Instructions

. . . 571

■ APPENDIX B SQL Data Types

. . . 579

■ APPENDIX C SQL Primer

. . . 591

■ APPENDIX D Sample Database Tables

. . . 597

■ INDEX

. . . 607
(2)

v

Contents

About the Author

. . . xix

About the Technical Reviewers

. . . xxi

Acknowledgments

. . . xxiii

Introduction

. . . xxv

■ CHAPTER 1 Data Sources and the Web

. . . 1

Are Data-Driven Web Sites a Good Idea?

. . . 2

How Do Web Sites Use Data Sources?

. . . 4

Database Uses in a Web Environment

. . . 4

How Does the Web Site Get the Data?

. . . 6

Looking for Information

. . . 8

Database Servers

. . . 8

Flat Files

. . . 9

Web Services

. . . 10

Objects

. . . 10

Services

. . . 10

Introducing ADO.NET

. . . 11

Data Access Technology: A Brief History

. . . 11

Data Providers

. . . 13

Data Source Controls

. . . 18

Developing Your First Example

. . . 18

Try It Out: Creating a Simple Data-Driven Page

. . . 19

How It Works

. . . 25

Summary

. . . 26

■ CHAPTER 2 Introducing Relational Databases

. . . 27

The Databases and Tools

. . . 28

Tables, Rows, and Columns

. . . 28

Try It Out: Creating a Table in SQL Server 2005

. . . 31

How It Works

. . . 35

Try It Out: Creating a Table in MySQL 5.0

. . . 36

How It Works

. . . 39

Column Properties and Constraints

. . . 40
(3)

vi C O N T E N T S

Queries and Stored Procedures

. . . 42

SQL Queries

. . . 42

Stored Procedures

. . . 46

Indexes

. . . 46

Types of Index

. . . 48

Try It Out: Adding Indexes in SQL Server 2005

. . . 48

How It Works

. . . 50

Try It Out: Adding Indexes in MySQL 5.0

. . . 51

How It Works

. . . 52

Relationships Between Tables

. . . 52

Types of Relationship

. . . 53

Foreign Keys and Foreign Key Constraints

. . . 56

Try It Out: Adding Relationships in SQL Server 2005

. . . 58

How It Works

. . . 61

Try It Out: Adding Relationships in MySQL 5.0

. . . 61

How It Works

. . . 63

Database Diagrams

. . . 64

Try It Out: Creating a Database Diagram in SQL Server 2005

. . . 64

How It Works

. . . 65

Try It Out: Using a Database Diagram to Create a New Relationship in SQL Server 2005

. . . 66

How It Works

. . . 67

Users, Roles, and Permissions

. . . 68

Try It Out: Creating User Accounts in SQL Server 2005

. . . 69

How It Works

. . . 70

Try It Out: Creating User Accounts in MySQL 5.0

. . . 71

How It Works

. . . 71

Data for the Sample Database

. . . 72

Try It Out: Adding Data to a SQL Server 2005 Database

. . . 72

How It Works

. . . 72

Try It Out: Adding Data to a MySQL 5.0 Database

. . . 73

How It Works

. . . 73

Database Views and Triggers

. . . 74

Summary

. . . 74
(4)

C O N T E N T S vii

■ CHAPTER 3 Displaying Data on a Page

. . . 77

Introducing the Data Source Web Controls

. . . 78

Introducing SELECT Queries

. . . 79

Try It Out: Querying a Single Table

. . . 79

How It Works

. . . 85

Try It Out: Ordering the Results

. . . 90

How It Works

. . . 92

Try It Out: Querying Multiple Tables

. . . 94

How It Works

. . . 96

Try It Out: Filtering the Results

. . . 99

How It Works

. . . 103

Try It Out: Filtering Results and Showing All Results

. . . 106

How It Works

. . . 108

Introducing the WHERE Clause

. . . 108

Using Comparison Operators

. . . 109

Using Logical Operators

. . . 109

Using the IN and BETWEEN Operators

. . . 110

Connecting to MySQL 5.0 and Microsoft Access

. . . 111

Connection Strings

. . . 111

Parameters and Queries

. . . 112

Summary

. . . 113

■ CHAPTER 4 Database Access in Code

. . . 115

The Connection and Command Life Cycle

. . . 116

Connection Objects

. . . 117

Try It Out: Connecting to SQL Server 2005 Using SqlConnection

. . . 117

How It Works

. . . 119

Try It Out: Connecting to MySQL 5.0 Using OdbcConnection

. . . . 121

How It Works

. . . 123

Try It Out: Connecting to Microsoft Access Using OleDbConnection

. . . 124

How It Works

. . . 126

Connection Object Methods and Properties

. . . 126

Connection Pooling

. . . 127
(5)

viii C O N T E N T S

Command Objects

. . . 128

Creating a Command Object

. . . 129

Returning the Results

. . . 130

Filtering the Results

. . . 130

Try It Out: Modifying the Query

. . . 130

How It Works

. . . 134

Try It Out: Using Parameters in Queries

. . . 138

How It Works

. . . 138

Parameters and Queries

. . . 140

Command Object Methods and Properties

. . . 142

Scalar Commands

. . . 143

Scalar Functions

. . . 144

Try It Out: Using the ExecuteScalar() Method

. . . 144

How It Works

. . . 146

Error Handling

. . . 147

Try It Out: Catching and Handling Errors

. . . 147

How It Works

. . . 150

Summary

. . . 152

■ CHAPTER 5 DataReader and DataSet

. . . 155

The DataReader Object

. . . 156

How to Read Through a DataReader

. . . 157

Try It Out: Iterating Through a DataReader

. . . 159

How It Works

. . . 163

DataReader Properties and Methods

. . . 165

The DataSet Object

. . . 168

How to Fill a DataSet

. . . 169

Try It Out: Iterating Through a DataSet

. . . 173

How It Works

. . . 175

Creating a DataSet from Scratch

. . . 176

SqlDataSource—DataSet or DataReader?

. . . 185

DataSet vs. DataReader

. . . 185

Good Practices

. . . 187

Summary

. . . 187
(6)

C O N T E N T S ix

■ CHAPTER 6 Inline and List Binding

. . . 189

Data-Binding Techniques

. . . 189

Data Binding in Code

. . . 190

Data Binding and the SqlDataSource

. . . 191

Data-Aware Web Controls

. . . 191

Associating Data to the Web Control

. . . 192

Inline Binding

. . . 194

Try It Out: Inline Binding to a DataReader

. . . 195

How It Works

. . . 199

Try It Out: Inline Binding to a DataSet

. . . 201

How It Works

. . . 204

The Inline Binding Alternative

. . . 205

Try It Out: Showing Data from a DataReader

. . . 206

How It Works

. . . 207

Try It Out: Showing Data from a DataSet

. . . 208

How It Works

. . . 210

List Binding

. . . 211

Try It Out: Using Single-Value Lookup Lists with a DataReader

. . . 213

How It Works

. . . 217

List Binding Events

. . . 219

Try It Out: Using Lookup Lists and Events with a DataReader

. . . 220

How It Works

. . . 223

Try It Out: Using Lookup Lists and Events with a DataSet

. . . 225

How It Works

. . . 228

Try It Out: Using Lookup Lists and Events with a SqlDataSource

. . . 229

How It Works

. . . 231

Connecting to Other Data Sources

. . . 235

Multiple Selection Lists

. . . 236

Try It Out: Using Multiple-Value Lookup Lists with a DataReader

. . . . 236

How It Works

. . . 240

Try It Out: Using Multiple-Value Lookup Lists with a SqlDataSource

. . . 242

How It Works

. . . 243

Summary

. . . 244
(7)

x C O N T E N T S

■ CHAPTER 7 Table Binding

. . . 247

The Table-Binding Web Controls

. . . 247

Repeater, DataList, and GridView Differences

. . . 249

Item Templates

. . . 250

The Repeater Web Control

. . . 251

The Repeater Templates

. . . 252

Try It Out: Using the Repeater to Display the Manufacturers

. . . 252

How It Works

. . . 257

The Repeater Control Events

. . . 260

Try It Out: Using the Repeater to Display the Players

. . . 260

How It Works

. . . 265

Inline Binding vs. Event-Based Binding

. . . 269

Inline Binding Alternative

. . . 269

Mixing Binding Types

. . . 270

The DataList Web Control

. . . 270

Try It Out: Using the DataList to Display the Players

. . . 270

How It Works

. . . 273

The GridView Web Control

. . . 274

Try It Out: Showing Data in a GridView

. . . 274

How It Works

. . . 275

GridView Customization

. . . 276

Try It Out: Customizing the GridView

. . . 281

How It Works

. . . 283

Paging and Sorting

. . . 286

Try It Out: Sorting the GridView

. . . 286

How It Works

. . . 288

Try It Out: Paging the GridView

. . . 288

How It Works

. . . 290

GridView Events

. . . 290

Try It Out: Responding to Events

. . . 290

How It Works

. . . 293

DataSet vs. DataReader

. . . 294

Summary

. . . 295
(8)

C O N T E N T S xi

■ CHAPTER 8 Writing to the Database

. . . 297

Making Changes to a Database

. . . 297

Inserting Data into the Database

. . . 298

The INSERT Query

. . . 298

Working to the Database’s Rules

. . . 300

Try It Out: Inserting a New Player with INSERT

. . . 300

How It Works

. . . 306

Queries in MySQL 5.0 and Microsoft Access

. . . 311

Try It Out: Setting the Player’s Supported Formats

. . . 312

How It Works

. . . 317

Validating Data

. . . 319

Try It Out: Validating Entered Data

. . . 321

How It Works

. . . 325

Deleting Data from the Database

. . . 328

The DELETE Query

. . . 329

Sympathy for the User: GridView ButtonField Columns

. . . 329

Try It Out: Deleting Players with DELETE

. . . 331

How It Works

. . . 334

Updating Data in the Database

. . . 336

The UPDATE Query

. . . 336

Try It Out: Updating a Player with UPDATE

. . . 336

How It Works

. . . 342

Using a DataSet to Make the Changes

. . . 346

The Role of the DataAdapter

. . . 347

The Role of the DataRow

. . . 348

Try It Out: Inserting Data Using a DataSet

. . . 348

How It Works

. . . 353

Try It Out: Updating Data Using a DataSet

. . . 356

How It Works

. . . 359

Try It Out: Deleting Data Using a DataSet

. . . 361

How It Works

. . . 363

Manually Creating the Commands

. . . 364

Summary

. . . 365
(9)

xii C O N T E N T S

■ CHAPTER 9 The GridView Family

. . . 367

The Updatable SqlDataSource

. . . 368

The GridView and DetailsView

. . . 369

The Field Controls

. . . 369

The EmptyDataTemplate

. . . 369

The Eval() and Bind() Methods

. . . 370

Editing Data in a GridView

. . . 371

Try It Out: Updating Data in a GridView

. . . 371

How It Works

. . . 375

Try It Out: Changing Controls Used for Editing

. . . 382

How It Works

. . . 383

Try It Out: Deleting Data in a GridView

. . . 385

How It Works

. . . 386

Using the DetailsView

. . . 387

Try It Out: Showing Data in a DetailsView

. . . 388

How It Works

. . . 390

Try It Out: Editing Data in a DetailsView

. . . 392

How It Works

. . . 394

Try It Out: Deleting Data in a DetailsView

. . . 395

How It Works

. . . 397

Try It Out: Adding Data in a DetailsView

. . . 397

How It Works

. . . 398

Tidying Up the User Interface

. . . 399

Try It Out: Manually Adding an Add New Player Link

. . . 400

How It Works

. . . 402

Using the FormView

. . . 403

Using Templates with the FormView

. . . 404

Switching Modes

. . . 406

Validating User Responses

. . . 406

Try It Out: Adding Validation to the DetailsView

. . . 408

How It Works

. . . 411

Summary

. . . 412
(10)

C O N T E N T S xiii

■ CHAPTER 10 Stored Procedures

. . . 415

Why Should You Use Stored Procedures?

. . . 415

Configuring MySQL 5.0 to Use Stored Procedures

. . . 416

Creating Stored Procedures

. . . 418

Try It Out: Creating a Stored Procedure in SQL Server 2005

. . . 418

How It Works

. . . 421

Try It Out: Creating a Stored Procedure in MySQL 5.0

. . . 422

How It Works

. . . 424

Granting Permissions for Stored Procedures

. . . 424

Calling Stored Procedures

. . . 425

Try It Out: Using a Command Object to Call a Stored Procedure

. . . 427

How It Works

. . . 429

Choosing an Execute Method

. . . 429

Try It Out: Calling a Stored Procedure in a SqlDataSource

. . . 430

How It Works

. . . 430

Altering and Deleting Stored Procedures

. . . 430

Try It Out: Modifying a Stored Procedure in SQL Server 2005

. . . 431

How It Works

. . . 432

Try It Out: Modifying a Stored Procedure in MySQL 5.0

. . . 433

How It Works

. . . 434

Creating Stored Procedures with Input Parameters

. . . 434

Try It Out: Creating a Stored Procedure with Input Parameters in SQL Server 2005

. . . 436

How It Works

. . . 438

Try It Out: Creating a Stored Procedure with Input Parameters in MySQL 5.0

. . . 439

How It Works

. . . 440

Passing Parameters to Stored Procedures

. . . 441

Try It Out: Using Input Parameters with a Command Object

. . . 441

How It Works

. . . 443

Try It Out: Using Input Parameters with a SqlDataSource

. . . 444

How It Works

. . . 444

Using Parameters with MySQL 5.0

. . . 445
(11)

xiv C O N T E N T S

Returning Data Using Output Parameters

. . . 445

Try It Out: Creating a Stored Procedure with Output Parameters in SQL Server 2005

. . . 446

How It Works

. . . 448

Try It Out: Creating a Stored Procedure with Input Parameters in MySQL 5.0

. . . 448

How It Works

. . . 449

Returning Parameters from Stored Procedures

. . . 450

Try It Out: Using Output Parameters with a SqlCommand Object

. . . 451

How It Works

. . . 452

Try It Out: Using Output Parameters with a SqlDataSource

. . . 453

How It Works

. . . 454

Using Stored Procedures with Other Queries

. . . 455

Summary

. . . 457

■ CHAPTER 11 Modifying the Database Structure

. . . 459

Using Command-Line Tools

. . . 460

Using SQLCMD

. . . 460

Try It Out: Querying a SQL Server Database via the Command Line

. . . 461

How It Works

. . . 463

Using mysql.exe

. . . 463

Try It Out: Querying a MySQL Database via the Command Line

. . . 464

How It Works

. . . 465

Creating Databases

. . . 466

Try It Out: Creating a Database with CREATE DATABASE

. . . 466

How It Works

. . . 468

Creating Tables

. . . 469

Try It Out: Creating Tables in SQL Server with CREATE TABLE

. . . 469

How It Works

. . . 471

Try It Out: Creating Tables in MySQL with CREATE TABLE

. . . 473

How It Works

. . . 475

Adding, Modifying, and Removing Columns

. . . 475

Try It Out: Changing a Table Definition with ALTER TABLE

. . . 477
(12)

C O N T E N T S xv

Creating and Deleting Indexes

. . . 480

Creating Indexes

. . . 480

Try It Out: Creating Indexes with CREATE INDEX

. . . 481

How It Works

. . . 482

Deleting Indexes

. . . 483

Try It Out: Deleting an Index with DROP INDEX

. . . 483

How It Works

. . . 484

Creating and Deleting Relationships

. . . 485

Creating Relationships

. . . 485

Try It Out: Creating Relationships with ALTER TABLE

. . . 486

How It Works

. . . 488

Deleting Relationships

. . . 489

Try It Out: Deleting Relationships with ALTER TABLE

. . . 490

How It Works

. . . 490

Deleting Tables

. . . 490

Try It Out: Deleting Database Tables with DROP TABLE

. . . 491

How It Works

. . . 493

Deleting Databases

. . . 493

Try It Out: Deleting a Database

. . . 494

How It Works

. . . 496

Summary

. . . 496

■ CHAPTER 12 Useful Techniques

. . . 497

Concurrency

. . . 498

Try It Out: Handling Concurrency Using Command Objects

. . . 499

How It Works

. . . 505

Try It Out: Handling Concurrency Using the SqlDataSource

. . . 507

How It Works

. . . 511

Caching

. . . 514

Specifying the Life Span of a Cached Object

. . . 516

Try It Out: Caching the Manufacturers

. . . 517

How It Works

. . . 519

Caching a DataSet

. . . 520

Removing Objects from the Cache

. . . 521

Try It Out: Removing Cached Objects Manually

. . . 521

How It Works

. . . 522
(13)

xvi C O N T E N T S

Transactions

. . . 523

Defining Database Transactions

. . . 526

Using a Transaction Object

. . . 527

Try It Out: Using a Transaction Object

. . . 528

How It Works

. . . 532

Implementing Distributed Transactions

. . . 534

Try It Out: Using a Local Transaction

. . . 536

How It Works

. . . 539

Try It Out: Using a Distributed Transaction

. . . 540

How It Works

. . . 542

Multiple Result Sets

. . . 542

Try It Out: Executing Two SELECT Queries in a Query Batch

. . . 543

How It Works

. . . 544

Summary

. . . 545

■ CHAPTER 13 Application Design and Implementation

. . . 547

The Software Life Cycle

. . . 548

Analysis

. . . 548

Client Requirements

. . . 548

The Right Tools

. . . 552

Design

. . . 553

Database Design

. . . 554

Application Design

. . . 559

Implementation

. . . 563

Prototypes

. . . 563

Stored Procedures

. . . 564

Code Issues

. . . 564

Testing and Debugging

. . . 565

Unit Testing

. . . 566

Measuring Performance

. . . 566

Maintenance

. . . 567

Bug Fixes

. . . 567

Feature Requests

. . . 568

Issue Tracking

. . . 568

Summary

. . . 568
(14)

C O N T E N T S xvii

■ APPENDIX A Installation Instructions

. . . 571

.NET Framework 2.0 Installation

. . . 571

Microsoft Jet Engine Installation

. . . 571

Visual Web Developer 2005 Express Edition Installation

. . . 572

SQL Server 2005 Express Edition Installation

. . . 573

SQL Server 2005 Management Studio Express Installation

. . . 576

MySQL 5.0 Installation

. . . 576

MySQL Query Browser 1.1 Installation

. . . 577

MySQL Connector/ODBC 3.51 Installation

. . . 578

MySQL Connector/NET 1.0 Installation

. . . 578

■ APPENDIX B SQL Data Types

. . . 579

Text Types

. . . 579

char

. . . 580

longtext

. . . 580

mediumtext

. . . 580

nchar/national char

. . . 580

nvarchar/national varchar

. . . 581

ntext

. . . 581

text

. . . 581

tinytext

. . . 582

varchar

. . . 582

Numeric Types

. . . 582

Autonumbers

. . . 582

Integer Types

. . . 583

decimal

. . . 585

Variable-Size Floating-Point Numbers

. . . 585

Date and Time Types

. . . 586

date

. . . 586

datetime

. . . 587

smalldatetime

. . . 587

time

. . . 587

timestamp

. . . 587

year

. . . 588
(15)

xviii C O N T E N T S

Binary Types

. . . 588

SQL Server Binary Types

. . . 588

MySQL Binary Types

. . . 589

Microsoft Access Binary Data

. . . 589

Miscellaneous Types

. . . 589

enum('value1','value2',...)

. . . 589

money

. . . 590

set('value1','value2',...)

. . . 590

smallmoney

. . . 590

uniqueidentifier

. . . 590

■ APPENDIX C SQL Primer

. . . 591

SELECT

. . . 591

INSERT

. . . 593

UPDATE

. . . 594

DELETE

. . . 594

■ APPENDIX D Sample Database Tables

. . . 597

The Manufacturer Table

. . . 598

The Player Table

. . . 600

The Format Table

. . . 602

The WhatPlaysWhatFormat Table

. . . 603

Using the Database Scripts

. . . 605

Using a Script to Build the SQL Server 2005 Database

. . . 605

Using a Script to Build the MySQL 5.0 Database

. . . 606

■ INDEX

. . . 607

Referensi

Dokumen terkait

Methodology to carry out the research in Chapter 3, it is divided into several part, which are the mathematical modeling of the quadrotor system, experiment procedure

The research results show (1) Activities of teacher in the learning area at TK Pembina Magelang conducted in accordance with the procedure. Teachers carry out the activity

This chapter discusses about type of the study , place and time of the study, population and sample, instrument of the study, data collecting procedure, instrument try

The purpose of try out is to test or measure validity or reliability of research instrument. The writer would try out the instrument before it applied to give pre test

Find out more information on how to more about creating your own ebook and profiting from it without writing a single word yourself, and start making money online instantly. Check

• The heap sort algorithm starts by using procedure BUILD-HEAP to build a heap on the input array A[1. Since the maximum element of the array stored at the root A [1], it can be

g. If the result is valid, it means that the test items as the instrumentation of this study are suitable to be given.. Instrument of Validity and Reliability. After the try out,

IntrodUctIon Whilst dental implants have been in use for more than thirty years to replace missing teeth,1 it is unfortunate that a new disease has concurrently been created.2 The