• No results found

Beginning C# 5.0. Databases. Vidya Vrat Agarwal. Second Edition

N/A
N/A
Protected

Academic year: 2021

Share "Beginning C# 5.0. Databases. Vidya Vrat Agarwal. Second Edition"

Copied!
13
0
0

Loading.... (view fulltext now)

Full text

(1)

Databases

Second Edition

(2)

J

About the Author

xviii

About the Technical Reviewer

xix

Acknowledgments

xx

Introduction

xxi

Part

I:

Understanding

Tools and

Fundamentals Databases

1

Chapter

1:

Getting

and

Understanding

Your

Tools

3

Obtaining

Visual Studio 2012

4

Installing

SQL Server 2012

Express

4

Installing

and

Attaching

the

AdventureWorks

Sample

Database

5

Installing

the

AdventureWorks Database

5

Attaching

the

AdventureWorks

Sample

Database 6

Summary

14

Chapter

2:

Understanding

Relational Databases

15

What

Is

a

Database?

15

Choosing

Between

a

Spreadsheet

and

a

Database

16

Why

Use

a

Database?

16

Benefits of

Using

a

Relational Database

Management System

16

Comparing Desktop

and Server RDBMS

Systems

17

Desktop

Databases 17 Server Databases 17

The Database

Life

Cycle

18

(3)

Mapping

Cardinalities

19

Understanding Keys

21

Primary Keys

22

Foreign

Keys

22

Understanding

Data

Integrity

22

Entity Integrity

22 Referential

Integrity

23

Normalization

Concepts

23

Drawbacks of Normalization

24

Summary

24

Chapter

3:

Creating

Database and Tables

25

Launching

SQL

Server

Management

Studio

25

Types

of SQL Server

Databases

25

The

Architecture

of

a

SQL Server Database

27

Creating

a

Database

in

a

Simple

Way

28

Exploring

Database

Properties

31

Creating

Database with

Your

Own

Settings

32

Understanding

Table Fundamentals 34

SQL

Server Data

Types

for

Table Columns 35

Creating

aTable in

SQL

Server 35

Adding

an IDENTITYColumninaTable 36

Summary

39

Part

II:

Working

with

Database

awl XML

—41

Chapter

4:

Manipulating

Database Data

43

Inserting

Data

43

Try

It:

Inserting

aNew Row 43

(4)

How It Works 44

Inserting Multiple

Rows

Through

a

Single

INSERT Statement

45

Updating

Data

47

Try

It:

Updating

aRow 48 HowItWorks . 48

Deleting

Data

49

Summary

50

Chapter

5:

Querying

Databases

51

Retrieving

Data

51

Try

It:

Running

a

Simple Query

53

How It Works 53

Using

the WHERE Clause 54

Using Comparison Operators

56

Sorting

Data

57

Try

It:

Writing

anEnhanced

Query

58

How It Works 59

GROUP

BY Clause

59

Try

It:

Using

the GROUP BY Clause 59

How It Works 60

Pattern

Matching

61

Try

It:

Using

the Percent

(%)

Character 61

How It Works 62

Try

It:

Using

the Underscore

(J

Character 62

How It Works 63

Try

It:

Using

the

Square

Bracket

(0)

Characters 63

How It

Works

64

Try

It:

Using

the

Square

Bracket and Caret

([A ])

Characters 64 viii

(5)

How It Works

65

Aggregate

Functions

65

Try

It:

Using

the

MIN, MAX, SUM,

and AVG Functions 66

How It Works 66

Try

It:

Using

the COUNT Function 67

How It Works 68

DATETIME Functions

68

Try

It:

Using

T-SQL

Date and

Time

Functions 68

How It

Works

69

List

Operator

70

Try

It:

Using

the IN

Operator

70

How It Works 71

Try

It:

Using

the NOT IN

Operator

71

How It Works 72

Range Operator

73

Try

It:

Using

the BETWEEN

Operator

73

How It Works 74

Try

It:

Using

the NOT

BETWEEN

Operator

74

HowItWorks 75

Finding

NULL Values

75

Try

It:

Using

IS NULL

Operator

75

How It Works 75

Try

It:

Using

the IS NOT NULL

Operator

76 How

It Works

76

Joins

77

Inner Joins 77 Table

Aliasing

78 Outer

Joins

80 ix

(6)

Other Joins

83

Summary

83

Chapter

6:

Using

Stored

Procedures

85

Creating

Stored Procedures

85

Try

It:

Working

with Stored Procedures in SQL Server 86

HowIt Works 87

Try

It:

Creating

aStored Procedure withan

Input

Parameter 88

HowIt Works 89

Try

It:

Creating

aStored Procedure withan

Output

Parameter 89

How It Works 91

Modifying

Stored Procedures

92

Try

It:

Modifying

Your Trivial Stored Procedure 92

How It Works 94

Displaying

the Definition

of Stored Procedures

94

Try

It:

Viewing

the Definition

of Our Stored Procedure

95

How It Works 95

Renaming

Stored

Procedures

96

Try

It:

Renaming

aStored Procedure 96

How

It Works 97

Deleting

Stored Procedures

98

Try

It:

Deleting

aStored Procedure 98

Summary

99

Chapter

7:

Using

XML

101

Defining

XML

101

Why

XML

102

Benefits

of

Storing

Data As

XML

102

Understanding

XML Documents

103

(7)

Understanding

the XML Declaration

104

Converting

Relational

Data to XML

105

Using

FOR XML RAW 105

Try

It:

Using

FOR XML RAW

(Attribute-centric)

105

How It Works 106

Try

It:

Using

FOR XML RAW

(Element-centric)

106

How It Works 107

Try

It:

Renaming

therowElement 107

How It Works 108

Observations About XML RAW

Formatting

109

Using

FOR XML AUTO 109

Try

It:

Using

FOR XML AUTO 109

How It Works 110

Observations About XML AUTO

Formatting

110

Using

the XML

Datatype

111

Try

It:

Creating

aTabletoStore XML 111

How It Works 112

Try

It:

Storing

and

Retrieving

XMLDocuments 112

How It Works 113

Summary

113

Chapter

8:

Understanding

Transactions

115

What

Is

a

Transaction?

115

When to Use

Transactions

116

Understanding

ACID

Properties

116

Transaction

Design

117

Transaction

State

118

Specifying

Transaction Boundaries 118

T-SQL

Statements Allowed inaTransaction 118 xi

(8)

Local Transactions in

SQL

Server 2012 119 Distributed Transactions in SQL Server 2012 120 GuidelinestoCode Efficient Transactions 120

HowtoCode

Transactions

121

Coding

Transactions

in

T-SQL

121

Summary

133

Part III:

Working

with Data

Using

ADO.NET

135

Chapter

9:

Building

Windows Forms

Applications

137

Understanding

Windows Forms

137

User Interface

Design

Principles

138 Best

Practices

for User Interface

Design

138

Position

of Controls 138

Fonts 140

Images

and Icons 140

Working

with

Windows

Forms 140

Understanding

the

Design

and CodeViews . 142

Sorting Properties

in the

Properties

Window 143

Categorized

View 144

Setting

the

Properties

of

Solutions, Projects,

and Windows Forms

146

Working

with Controls 147

Setting

Dock

and Anchor

Properties

152

Dock

Property

152

Anchor

Property

153

Adding

aNew Form to the

Project

156

Implementing

anMDI Form 162

Summary

170

(9)

Chapter

10:

Introduction

to AD0.NET

171

Understanding

ADO.NET

171

The Motivation Behind ADO.NET 172

Moving

from ADOtoADO.NET 172

ADO.NET Isn'taNew Version of ADO 173

ADO.NET

and

the

.NETBase

Class

Library

173

Understanding

ADO.NET Architecture

175

Understanding

.NET Data Providers 177

Understanding

the SQL Server Data Provider 178

Understanding

the OLE DB Data Provider 179

Understanding

the ODBC Data Provider 180

Data Providers Are APIs

181

Summary

182

Chapter

11:

Handling

Exceptions

183

The

System.Exception

Class

183

What Causes

an

Exception

to Occur

184

Try

It:

Creating

a

File-Handling Application

184

Try

It:

Causing

an

Exception

toOccur and

Observing

the Behavior 189

Exploring

the

Type,

Message,

and StackTrace

Properties

of

an

Exception

192

Handling Exceptions

194

Try

It:

Adding Exception-Handling

Statements

194

How It Works 195

Summary

196

Chapter

12:

Making

Connections

197

Introducing

the

Data Provider Connection Classes

197

Connecting

to

SQL

Server 2012

with

SqIConnection

198

Try

It:

Using SqIConnection

198 xiii

(10)

How It Works 200

Debugging

Connectionsto

SQL

Server 202

Security

and Passwords in

SqIConnection

203 How to Use

SQL

Server

Security

204

Connection

String

Parameters for

SqIConnection

204

Connection

Pooling

205

Improving

Your

Use of Connection

Objects

206

Using

the Connection

String

in the Connection Constructor 206

Displaying

Connection Information 206

Try

it:

Displaying

Connection Information 206

How It Works 208

Connecting

to SQL Server with OleDbConnection

210

Try

It:

Connecting

to SQL Server with the OLE DB Data Provider 210

How It Works 212

Summary

212

Chapter

13:

Executing

ADO.NET Commands

to Retrieve Data

213

Creating

a

Command

213

Assigning

Text toaCommand 213

Executing

Commands

217

Executing

Commands withaScalar

Query

217

Try

It:

Using

the ExecuteScalar

Method

217

Executing

Commands

with

Multiple

Results 221

Executing

Nonquery

Statements 224

Working

with Stored Procedures

232

Creating

aStored Procedure to PerformaDelete

Operation

232

Summary

239

(11)

Chapter

14:

Using

Data Readers

241

Understanding

Data Readers

in

General

241

Using

Ordinal Indexers 246

Using

Column Name

Indexers

250

Using Typed

Accessor Methods

251

Getting

Data

About

Data 258

Getting

Data About Tables 264

Using Multiple

Result

Sets with

aData Reader 268

Summary

273

Part IV:

Working

with Advanced ADO.NET Related Features

275

Chapter

15:

Using

Data Sets and Data

Adapters

277

Understanding

the

Object

Model

277

Data

Setsvs. Data Readers 278

A Brief

Introduction

to

Data Sets

278 A Brief Introduction to Data

Adapters

279 A Brief Introduction to Data

Tables,

Data

Columns,

and Data Rows 280

Working

with Data Sets and Data

Adapters

281

Filtering

and

Sorting

inaData Set 285

Comparing

FilterSortto

PopDataSet

291

Using

Data Views 292

Modifying

Datain aDataset 296

Propagating

Changes

toaData Source 300

InsertCommand

Property

301 Command Builders 304

Concurrency

308

Using

Data

Sets and

XML

308

Understanding Typed

and

Untyped

Data Sets 313

(12)

Summary

314

Chapter

16:

Using

Data Controls with ASP.NET

Applications

315

Understanding

Web

Functionality

315

The Web

Server

316

Understanding

ASP.NET and Web

Pages

316

Understanding

the

Visual Studio

2012

Web Site

Types

317

Understanding

the

Layout

of

an

ASP.NET Web Site

320

Understanding

the Web Ul

of ASP.NET Web

Apps

322

Using

the

Repeater

Control

326

How It Works

330

Summary

331

Chapter

17:

Working

with

Text and

Binary

Data

333

Understanding

SQL Server Text and

Binary

Data

Types

333

Storing

Images

in

a

Database

334

Retrieving Images

fromaDatabase 340

Working

with Text Data 346

Retrieving

Data from Text Columns 351

Summary

356

Chapter

18:

Using

LINQ

357

Introduction

to

LINQ

357

Architecture

of

LINQ

359

LINQ

Project

Structure

360

Using

LINQ to

Objects

361

Using

LINQ to

SQL

364

Using

LINQ

to XML 370

Summary

374

(13)

Chapter

19:

Using

the ADO.NET

Entity

Framework

375

Understanding

ADO.NET

Entity

Framework 5.0

375

Understanding

the

Entity

Data Model

376

Working

with the

Entity

Data Model 376

Summary

393

Chapter

20:

Using

the CLR in

SQL

Server

395

introducing

SQL

CLR

395

Choosing

Between

T-SQL

and

SQL

CLR

396

Enabling

SQL CLR

Integration

396

Creating

a

SQL

CLR Stored

Procedure

398

Try

It:

Creating

aSQL CLR Stored Procedure

Using

C# 398

How It Works 402

Deploying

a

SQL

CLR Stored Procedure into

SQL

Server

403

Try

It:

Deploying

SQLCLRC# Stored Procedure in SQL Server 403

How It Works 405

Executing

the

SQL CLR Stored Procedure

405

Try

It:

Executing

the

SQL

CLR Stored

Procedure

405

How It

Works

407

Summary

407

Index

409

References

Related documents

In addition to the three core courses, Professional Project option students must complete a minimum of two courses in each the Environmental Applied Science elective group (Group

There is no mediator between man and {his/her} salvation." "Salvation is the freeing of the soul from its bodily fetters, becoming a God through knowledge and wisdom, controlling

The cost for cosmetology transfer students is $11 .30 per hour and $10 .00 per hour for barbering students to attended at PAUL MITCHELL THE SCHOOL Fort Myers; this does not include

Por ende, por esta presente carta otorgo e conosco que do e otorgo todo mi poder conplido, libre e llenero, bastante poder segund que lo yo he e tengo e segund que mejor e

The drawn links between ethics, organization and social capital can be conceived as dividing forces which separate various movements such as open source software (FOSS) and

Like the human eye, the relative sensitivity of a photoconductive cell is dependent on the wavelength (color) of the incident light. Each photoconductor material

He has also served as Co-Chair on the Parent Volunteer Committee for Admission, participated in developing the SFDS Strategic Plan, and served on the Head of Upper School

А для того, щоб така системна організація інформаційного забезпечення управління існувала необхідно додержуватися наступних принципів: