Syed Fahad Gilani, Vidya Vrat Agarwal, Jon Reid, Ranga Raghuram, James Huddleston, Jacob Hammer Pedersen1590599004, 9781590599006, 9781430204503
A comprehensive tutorial on both SQL Server 2005 and ADO.NET 3.0, Beginning C# 2008 Databases explains and demonstrates how to create database objects and program against them in both T–SQL and C#. Full of practical, detailed examples, it’s been fully revised and updated for C# 2008 and offers the most complete, detailed, and gentle introduction to database technology for all C# programmers at any level of experience.
– Comprehensively and concisely explains fundamental database concepts and programming techniques
– Rich in working examples of both T–SQL and C# programs
– Covers all the features most database programming ever requires
What you’ll learn
– How relational databases work and how to use them
– How C# uses ADO.NET to access databases
– How to write stored procedures in T–SQL and call them from C# programs
– How to use XML in database applications
– How to use LINQ to simplify C# database programming
– How to install SQL Server 2005 Express and Visual C# 3.0
– Express and use them to teach yourself database programming by doing it
Who is this book for?
Beginning C# 2008 Databases is for every C# programmer. Database programming requires relatively little knowledge of C# but a lot of knowledge about relational database concepts and the database language SQL. This book assumes no prior database experience and teaches you, always through hands–on examples, how to create and use relational databases with SQL and how to access them with C#. Almost every application needs to access a database, and this book teaches all the fundamentals you needand may ever needto develop professional database applications.
About the Apress Beginning Series
The Beginning series from Apress is the right choice to get the information you need to land that crucial entry-level job. These books will teach you a standard and important technology from the ground up because they are explicitly designed to take you from “novice to professional.” You’ll start your journey by seeing what you need to know—but without needless theory and filler. You’ll build your skill set by learning how to put together real–world projects step by step. So whether your goal is your next career challenge or a new learning opportunity, the Beginning series from Apress will take you there—it is your trusted guide through unfamiliar territory!
Related Titles from Apress
– Beginning C# 2008: From Novice to Professional
– Beginning Database Design: From Novice to Professional
– Pro C# 2008 and the .NET 3.5 Platform, Fourth Edition
– Pro LINQ: Language Integrated Query in C# 2008
Table of contents :
Beginning C# 2008 Databases……Page 1
Contents at a Glance……Page 7
Contents……Page 9
About the Authors……Page 23
About the Technical Reviewer……Page 25
Acknowledgments……Page 27
What This Book Covers……Page 29
How to Download the Sample Code……Page 30
Getting Your Tools……Page 31
Obtaining Visual Studio 2008……Page 32
Installing SQL Server Management Studio Express……Page 33
Installing the Northwind Sample Database……Page 34
Installing the Northwind Creation Script……Page 35
Creating the Northwind Sample Database……Page 36
Installing the AdventureWorks Creation Script……Page 39
Creating the AdventureWorks Sample Database……Page 40
Summary……Page 43
Microsoft .NET Framework Versions and the Green Bit and Red Bit Assembly Model……Page 45
Using Microsoft Visual Studio 2008……Page 46
Try It Out: Creating a Simple Console Application Project Using Visual Studio 2008……Page 49
How It Works……Page 51
Using SQL Server Management Studio Express……Page 52
Summary……Page 56
What Is a Database?……Page 57
Why Use a Database?……Page 58
Comparing Desktop and Server RDBMS Systems……Page 59
Server Databases……Page 60
The Database Life Cycle……Page 61
Mapping Cardinalities……Page 62
Understanding Keys……Page 64
Foreign Keys……Page 65
Normalization Concepts……Page 66
Summary……Page 68
Writing Database Queries……Page 69
Comparing QBE and SQL……Page 70
Try It Out: Running a Simple Query……Page 71
Common Table Expressions……Page 72
Try It Out: Creating a CTE……Page 73
Try It Out: Using the GROUP BY Clause……Page 74
How It Works……Page 75
Try It Out: Using the PIVOT Operator……Page 76
How It Works……Page 77
Try It Out: Using the ROW_NUMBER() Function……Page 78
Try It Out: Using the PARTITION BY Clause……Page 79
Pattern Matching……Page 80
Try It Out: Using the % Character……Page 81
Try It Out: Using the _ (Underscore) Character……Page 82
How It Works……Page 83
How It Works……Page 84
Try It Out: Using the [^] (Square Bracket and Caret) Characters……Page 85
Try It Out: Using the MIN, MAX, SUM, and AVG Functions……Page 86
Try It Out: Using the COUNT Function……Page 87
How It Works……Page 88
Try It Out: Using T-SQL Date and Time Functions……Page 89
How It Works……Page 90
Inner Joins……Page 91
Try It Out: Writing an Inner Join……Page 92
How It Works……Page 93
Try It Out: Writing an Inner Join Using Correlation Names……Page 94
Try It Out: Writing an Inner Join of Three Tables……Page 95
How It Works……Page 96
Outer Joins……Page 97
Try It Out: Adding an Employee with No Orders……Page 98
Try It Out: Using LEFT OUTER JOIN……Page 99
How It Works……Page 100
Other Joins……Page 101
Summary……Page 102
Retrieving Data……Page 103
Try It Out: Running a Simple Query……Page 104
How It Works……Page 105
Try It Out: Refining Your Query……Page 106
How It Works……Page 107
Using Comparison Operators in a WHERE Clause……Page 108
Sorting Data……Page 110
Try It Out: Writing an Enhanced Query……Page 111
How It Works……Page 112
Try It Out: Creating a New Table……Page 113
How It Works……Page 114
How It Works……Page 116
Try It Out: Inserting a New Row……Page 118
How It Works……Page 119
How It Works……Page 121
Deleting Data……Page 123
Summary……Page 124
Creating Stored Procedures……Page 125
Try It Out: Working with a Stored Procedure in SQL Server……Page 126
How It Works……Page 127
Try It Out: Creating a Stored Procedure with an Input Parameter……Page 129
Try It Out: Creating a Stored Procedure with an Output Parameter……Page 130
How It Works……Page 132
Try It Out: Modifying the Stored Procedure……Page 133
How It Works……Page 135
Try It Out: Viewing the Definition of Your Stored Procedure……Page 136
Try It Out: Renaming a Stored Procedure……Page 137
Working with Stored Procedures in C#……Page 138
Try It Out: Executing a Stored Procedure with No Input Parameters……Page 139
Try It Out: Executing a Stored Procedure with Parameters……Page 141
How It Works……Page 144
Try It Out: Deleting a Stored Procedure……Page 145
How It Works……Page 146
Summary……Page 147
Defining XML……Page 149
Benefits of Storing Data As XML……Page 150
Understanding XML Documents……Page 151
Converting Relational Data to XML……Page 153
Try It Out: Using FOR XML RAW (Attribute Centric)……Page 154
Try It Out: Using FOR XML RAW (Element Centric)……Page 155
Try It Out: Renaming the row Element……Page 156
How It Works……Page 157
Try It Out: Using FOR XML AUTO……Page 158
Observations About FOR XML AUTO Formatting……Page 159
Try It Out: Creating a Table to Store XML……Page 160
Try It Out: Storing and Retrieving XML Documents……Page 161
Summary……Page 163
What Is a Transaction?……Page 165
When to Use Transactions……Page 166
Understanding ACID Properties……Page 167
Transaction State……Page 168
Local Transactions in SQL Server 2005……Page 169
Distributed Transactions in SQL Server 2005……Page 171
Guidelines to Code Efficient Transactions……Page 172
Try It Out: Coding a Transaction in T-SQL……Page 173
How It Works……Page 177
How It Works……Page 179
Try It Out: What Happens When Both Operations Fail……Page 180
Coding Transactions in ADO.NET……Page 181
Try It Out: Working with ADO.NET Transactions……Page 182
How It Works……Page 184
Summary……Page 186
Understanding ADO.NET……Page 187
The Motivation Behind ADO.NET……Page 188
ADO.NET Isn’t a New Version of ADO……Page 189
ADO.NET and the .NET Base Class Library……Page 190
Understanding ADO.NET Architecture……Page 192
Working with the SQL Server Data Provider……Page 194
Try It Out: Creating a Simple Console Application Using the SQL Server Data Provider……Page 195
How It Works……Page 198
Working with the OLE DB Data Provider……Page 201
Try It Out: Creating a Simple Console Application Using the OLE DB Data Provider……Page 202
How It Works……Page 206
Working with the ODBC Data Provider……Page 207
Creating an ODBC Data Source……Page 208
Try It Out: Creating a Simple Console Application Using the ODBC Data Provider……Page 214
How It Works……Page 216
Data Providers Are APIs……Page 217
Summary……Page 218
Introducing the Data Provider Connection Classes……Page 219
Try It Out: Using SqlConnection……Page 220
How It Works……Page 222
Debugging Connections to SQL Server……Page 225
Security and Passwords in SqlConnection……Page 226
Connection String Parameters for SqlConnection……Page 227
Displaying Connection Information……Page 229
Try It Out: Displaying Connection Information……Page 230
How It Works……Page 232
Connecting to SQL Server Express with OleDbConnection……Page 235
Try It Out: Connecting to SQL Server Express with the OLE DB Data Provider……Page 236
Summary……Page 238
Creating a Command……Page 239
Try It Out: Creating a Command with a Constructor……Page 240
Associating a Command with a Connection……Page 241
How It Works……Page 242
Try It Out: Setting the CommandText Property……Page 243
How It Works……Page 244
Executing Commands……Page 245
Try It Out: Using the ExecuteScalar Method……Page 246
How It Works……Page 248
Try It Out: Using the ExecuteReader Method……Page 249
How It Works……Page 251
Try It Out: Using the ExecuteNonQuery Method……Page 252
How It Works……Page 255
Command Parameters……Page 257
Try It Out: Using Command Parameters……Page 258
How It Works……Page 262
Summary……Page 263
Understanding Data Readers in General……Page 265
Try It Out: Looping Through a Result Set……Page 266
How It Works……Page 268
Using Ordinal Indexers……Page 269
Try It Out: Using Ordinal Indexers……Page 270
How It Works……Page 272
Using Column Name Indexers……Page 273
Using Typed Accessor Methods……Page 274
Try It Out: Using Typed Accessor Methods……Page 277
How It Works……Page 279
Try It Out: Getting Information About a Result Set with a Data Reader……Page 281
How It Works……Page 285
Try It Out: Getting Schema Information……Page 286
How It Works……Page 288
Using Multiple Result Sets with a Data Reader……Page 289
Try It Out: Handling Multiple Result Sets……Page 290
How It Works……Page 292
Summary……Page 294
Using Datasets and Data Adapters……Page 295
A Brief Introduction to Datasets……Page 296
A Brief Introduction to Data Adapters……Page 298
A Brief Introduction to Data Tables, Data Columns, and Data Rows……Page 299
Try It Out: Populating a Dataset with a Data Adapter……Page 300
How It Works……Page 303
Try It Out: Dynamically Filtering and Sorting Data in a Dataset……Page 304
How It Works……Page 307
Comparing FilterSort to PopDataSet……Page 310
Try It Out: Refining Data with a Data View……Page 311
How It Works……Page 314
Try It Out: Modifying a Data Table in a Dataset……Page 315
How It Works……Page 318
UpdateCommand Property……Page 319
Try It Out: Propagating Dataset Changes to a Data Source……Page 320
How It Works……Page 324
Try It Out: Propagating New Dataset Rows to a Data Source……Page 325
How It Works……Page 329
Try It Out: Propagating New Dataset Rows to a Data Source……Page 331
How It Works……Page 334
Try It Out: Using SqlCommandBuilder……Page 336
How It Works……Page 339
Concurrency……Page 340
Using Datasets and XML……Page 341
Try It Out: Extracting a Dataset to an XML File……Page 342
How It Works……Page 344
Try It Out: Populating a Data Table with a Data Adapter……Page 345
How It Works……Page 347
Understanding Typed and Untyped Datasets……Page 348
Summary……Page 349
Understanding Windows Forms……Page 351
Simplicity……Page 352
Consistency……Page 353
Fonts……Page 354
Working with Windows Forms……Page 355
Understanding the Design and Code Views……Page 357
Sorting Properties in the Properties Window……Page 358
Categorized View……Page 359
Setting Properties of Solutions, Projects, and Windows Forms……Page 360
Working with Controls……Page 361
Try It Out: Working with the TextBox and Button Controls……Page 362
Setting Dock and Anchor Properties……Page 365
Anchor Property……Page 366
Try It Out: Working with the Dock and Anchor Properties……Page 367
Try It Out: Adding a New Form to the Windows Project……Page 370
Try It Out: Setting the Startup Form……Page 371
Implementing an MDI Form……Page 372
Try It Out: Creating an MDI Parent Form with a Menu Bar……Page 373
Try It Out: Creating an MDI Child Form and Running an MDI Application……Page 374
How It Works……Page 376
Summary……Page 377
Understanding Web Functionality……Page 379
The Web Browser and HTTP……Page 380
Understanding the Visual Studio 2008 Web Site Types……Page 381
File System Web Site……Page 382
HTTP Web Site……Page 383
Layout of an ASP.NET Web Site……Page 384
Web Pages……Page 385
The web.config File……Page 387
Try It Out: Working with a Web Form……Page 388
Try It Out: Working with Split View……Page 389
Using Master Pages……Page 392
Try It Out: Working with a Master Page……Page 393
Summary……Page 398
Try It Out: Handling an ADO.NET Exception (Part 1)……Page 399
How It Works……Page 403
Try It Out: Handling an ADO.NET Exception (Part 2)……Page 405
How It Works……Page 408
Handling Database Exceptions……Page 409
Try It Out: Handling a Database Exception (Part 1): RAISERROR……Page 410
How It Works……Page 413
Try It Out: Handling a Database Exception (Part 2): Stored Procedure Error……Page 415
How It Works……Page 417
Try It Out: Handling a Database Exception (Part 3): Errors Collection……Page 418
Summary……Page 420
Understanding Events……Page 421
Design of Events……Page 422
Common Events Raised by Controls……Page 423
Try It Out: Creating an Event Handler……Page 424
Try It Out: Working with Mouse Movement Events……Page 426
Try It Out: Working with the Keyboard’s KeyDown and KeyUp Events……Page 430
Try It Out: Working with the Keyboard’s KeyPress Event……Page 431
Summary……Page 432
Understanding SQL Server Text and Binary Data Types……Page 433
Storing Images in a Database……Page 434
Try It Out: Loading Image Binary Data from Files……Page 435
How It Works……Page 440
Try It Out: Displaying Stored Images……Page 443
How It Works……Page 447
Try It Out: Loading Text Data from a File……Page 449
How It Works……Page 454
Retrieving Data from Text Columns……Page 455
Try It Out: Retrieving Text Data……Page 456
How It Works……Page 459
Summary……Page 460
Using LINQ……Page 461
Introduction to LINQ……Page 462
Architecture of LINQ……Page 463
LINQ Project Structure……Page 465
Try It Out: Coding a Simple LINQ to Objects Query……Page 467
Try It Out: Coding a Simple LINQ to SQL Query……Page 469
How It Works……Page 472
Try It Out: Using the where Clause……Page 474
Try It Out: Coding a Simple LINQ to XML Query……Page 475
Summary……Page 477
Understanding ADO.NET 3.5 Entity Framework……Page 479
Understanding the Entity Data Model……Page 480
Working with the Entity Data Model……Page 481
Try It Out: Creating an Entity Data Model……Page 483
How It Works……Page 491
Try It Out: Schema Abstraction Using an Entity Data Model……Page 492
Summary……Page 495
Index……Page 497
Reviews
There are no reviews yet.