Tài liệu Professional ADO.NET Programming pdf

748 1.1K 5
Tài liệu Professional ADO.NET Programming pdf

Đang tải... (xem toàn văn)

Tài liệu hạn chế xem trước, để xem đầy đủ mời bạn chọn Tải xuống

Thông tin tài liệu

Summary of Contents Introduction 1 Chapter 1: Data Access and .NET 9 Chapter 2: The .NET Data Providers 45 Chapter 3: Visual Studio .NET and ADO.NET 69 Chapter 4: Using DataReaders 133 Chapter 5: The DataSet 163 Chapter 6: Using the DataAdapter 207 Chapter 7: Typed DataSets and DataSet Schemas 235 Chapter 8: XML and the DataSet 271 Chapter 9: Constraints, Relations, and Views 317 Chapter 10: Transactions 365 Chapter 11: Mapping 387 Chapter 12: Making a Data Services Component 409 Chapter 13: ADO.NET and Web Services 455 Chapter 14: SQL Server Native XML Support 517 Chapter 15: Performance and Security 551 Chapter 16: Integration and Migration 589 Chapter 17: Creating a Custom .NET Data Provider 625 Chapter 18: Case Study – Cycle Couriers 671 Index 707 Table of Contents Introduction 1 What Is ADO.NET? 1 What Does This Book Cover? 1 Who Is This Book For? 3 What You Need To Use This Book 3 Conventions 3 Customer Support 4 How to Download the Sample Code for the Book 4 Errata 4 E-mail Support 4 p2p.wrox.com 5 Why this System Offers the Best Support 6 Chapter 1: Data Access and .NET 9 The .NET Framework 9 The Common Language Runtime 10 Garbage Collection 11 The Common Language Infrastructure 11 Assemblies 11 The Common Type System 12 The Common Language Specification 12 .NET Class Libraries 12 Not Another Data Access Technology? 13 Brief History of Data Access 13 ODBC 13 DAO 13 RDO 14 OLE DB 14 ADO 14 Introduction to ADO.NET 15 Advantages of Using Managed Classes 15 Cross-Language Support 15 Cleaner Architecture 15 XML Support 15 Optimized Object Model 16 Table of Contents ii Architectural Overview of ADO.NET 16 .NET Data Providers 16 Data Provider Components 16 Existing Data Providers 19 The DataSet 21 The DataTable Class 23 Updating the Data Source 24 ADO.NET and XML 25 Typed DataSets 27 ADO.NET and ADO 2.6 28 Disconnected Data Access 29 Read-Only, Forward-Only Access 30 Provider-Specific Classes 31 Using ADO 2.x in .NET 34 Using ADO.NET 36 C# Example 36 Visual Basic.NET Example 36 JScript.NET Example 37 Managed C++ Example 38 J# Example 39 ADO.NET Events 40 Summary 42 Chapter 2: The .NET Data Providers 45 The SQL Server Data Provider 46 The OLE DB Data Provider 47 Meet the Players 47 Connection 48 Command 49 DataReader 49 DataAdapter 52 Establishing Connections 53 The SqlConnection and OleDbConnection Classes 53 Constructing a Connection 53 Storing Connection Strings in the Configuration File 54 Connection Events 56 Connection Pooling in the Data Providers 58 Using Commands 59 The SqlCommand and OleDbCommand Classes 59 Using a Command with a T-SQL Statement 59 Executing the Command 60 Using a Command with a Stored Procedure 63 Using the SqlParameter and OleDbParameter Classes 64 Summary 67 Table of Contents iii Chapter 3: Visual Studio .NET and ADO.NET 69 Connection Classes 70 SqlConnection and OleDbConnection Data Components 70 Adding the Connection String 72 Retrieving Connection Strings Programmatically 76 Adding an Event 77 Command Data Components 79 SqlCommand and OledbCommand Data Components 80 Defining a Query Command 81 Executing a Stored Procedure 87 Data Adapter Components 91 Table Mappings 101 DataSet Data Component 103 The Typed Dataset 104 Adding a Typed Dataset to the Project 104 Relating Two or More Tables 108 Generating and Filling a Typed DataSet Object 110 Using the Techniques Acquired to Create a Web Service 112 The DataView Data Component 116 Using the DataView to View Selected Rows 117 Filtering Rows Using a Filter Expression 117 Filtering Rows on Row State 118 Using the DataView to Sort Rows 119 The DataGrid Component 120 DataGrid Web Component 120 Binding the DataGrid Component to a Data Source 120 Formatting the DataGrid 122 Sorting DataGrid Records 125 Selecting, Editing, Updating, and Deleting DataGrid Records 125 Breaking a DataGrid into Pages 128 DataGrid Window Component 129 Summary 130 Chapter 4: Using DataReaders 133 A Note About the Chapter Contents 134 The Basics of a DataReader 135 The IDataReader Interface 135 The IDataRecord Interface 135 The ADO.NET DataReaders 136 DataReader Operations 138 Creating a DataReader 139 The ExecuteReader Method 139 Creating and Using a DataReader 140 Table of Contents iv Simple Data Retrieval With the DataReader 141 Executing Stored Procedures with a DataReader 143 Navigating Multiple Result Sets 147 Accessing the Data in a Type-Safe Manner 148 SQL Server Types 150 Getting the Result Set's Schema 151 Bringing it all Together 153 Commonly Encountered Exceptions 157 IndexOutOfBoundsException 157 InvalidOperationException 158 DataReader Performance Considerations 158 Column Ordinal versus Column Name 159 Type Safe Access versus Non-Type-Safe Access 160 Summary 161 Chapter 5: The DataSet 163 The DataTable 164 DataColumn 165 DataRow 166 Constraints 166 Primary Key 167 Dynamically Constructing a DataTable 168 DataTable Events 169 DataTable Events Example 170 Populating a DataSet 180 Constructing a DataAdapter 181 Invoking Fill 182 DataAdapter Example 183 The Tables Collection 185 Populating the Tables Collection with Multiple DataTables 185 Multiple DataSet Tables Example 186 Retrieving the Tables Collection Metadata 188 The Relations Collection 190 DataRelations Example 192 Merging DataSets 197 Merging Two DataSets 198 Merging Two DataSets and Maintaining Original Values 198 Merging Two DataSets with Different Schemas 198 Caching DataSets for Better Performance 199 Summary 204 Table of Contents v Chapter 6: Using the DataAdapter 207 The DataAdapter Base Class 207 DataAdapter and DataSet 208 More Details for the Fill Method 212 Using More Complex Queries 213 Filling a DataSet Object with Few Records 217 Filling a DataSet Object with Only the Schema 219 Filling a DataSet Object that Already has a Schema 222 Updating a Database 222 Using a CommandBuilder Object 223 Using SQL Commands 225 Making Updates Using Stored Procedures 228 The DataAdapter's Events 230 Summary 232 Chapter 7: Typed DataSets and DataSet Schemas 235 Overview of XSD 236 Simple Types 236 Basic Data Types 236 Attributes 238 Enumerations 239 User-Defined Types 240 Facets 240 Complex Types 241 Mixed Attribute 241 Element Groups 242 ll Element 242 choice Element 242 sequence Element 243 group Element 243 Attribute Groups 244 XSD Annotation 244 documentation Element 245 appinfo Element 245 XmlSchema Class 245 DataSet Schemas 247 Schema Translation 247 Generating Tables and Columns 248 Constraints 250 Keys 250 Unique Constraints 250 Foreign Keys (Keyrefs) and Relationships 250 Typed DataSets 254 Building Strongly Typed DataSets in Visual Studio .NET 255 Building Typed DataSets Manually 259 Strongly Typed DataSets and Relational Data 260 Typed DataSet Performance 262 Table of Contents vi Annotating Typed DataSets 262 codegen 263 typedName 263 typedPlural 263 typedParent 263 typedChildren 263 nullValue 263 msdata 264 ConstraintName 264 ConstraintOnly 264 UpdateRule 264 DeleteRule 264 PrimaryKey 264 Relationship 264 Annotated Typed DataSet Example 265 Summary 268 Chapter 8: XML and the DataSet 271 XmlDocument (W3C DOM) 272 XPath 275 Axis 276 Node Test 277 Predicate 277 DataSet Schemas 280 Schema Inference 280 Inference Rules 280 Inference Rules in Action 281 Supplied Schemas 285 Document Validation with Schemas 286 XmlValidatingReader 286 DataSets and XML Data 289 Loading XML 289 XmlReadMode 290 Writing XML 291 Fidelity Loss and DataSet Schemas 293 DataSet Marshaling 295 DataSet Serialization 295 Transferring DataSet XML Between Applications 295 Data Filtering 299 Select Method 300 Data Views 303 The DataSet and the XmlDataDocument 305 Relational Projection of DOM View via XSD 306 Relational Projection Views with a Typed DataSet 309 Using XSL and XSLT Transformations 310 Summary 314 Table of Contents vii Chapter 9: Constraints, Relations, and Views 317 Constraints 318 Unique Constraint 319 ForeignKeyConstraint 321 Custom Constraint 326 DataRelations 333 XML and DataRelations 337 DataViews 340 Sorting 341 Filtering 343 Operators 344 Relationship Referencing 344 Aggregate Functions 345 Functions 346 Filtering on Row State 346 Editing Data in the DataView 348 DataViewManager 349 Databinding 350 Bringing it Together 352 Examples 354 Example 1 354 Example 2 357 Summary 362 Chapter 10: Transactions 365 What is a Transaction? 365 ACID Properties 366 Database Transactions 366 Transaction Vocabulary 367 ADO.NET Transaction Support 367 Transaction Class 369 Methods of the Transaction class 369 Writing Transactional Database Applications 370 Implementing Transactions 370 Running the Application 373 Examining the Effect of Isolation Level 373 What are Isolation Levels? 374 Some Related Terms 374 Possible Isolation Levels in ADO.NET 374 Changing Isolation Levels 375 When to Use Transactions 377 Transactions and Performance 378 Default Behavior for Transactions 378 Transactions and User Confirmation 378 Simultaneous ADO.NET and DBMS Transactions 379 Table of Contents viii Advanced Techniques 379 Savepoints 379 Nested Transactions 382 Using Transactions with a DataSet and DataAdapter 382 Summary 384 Chapter 11: Mapping 387 Using the SQL AS Keyword 387 The ADO.NET Mapping Mechanism 389 Using Mapping when Retrieving Data 389 The MissingMappingAction and MissingSchemaAction Properties 392 Inserting Records Using Mapped Names 393 Web Services with Mapping 396 Creating the Supplier Database 398 Creating the Supplier Web Service 400 Creating the Pet Lovers Application 401 Summary 406 Chapter 12: Making a Data Services Component 409 Installing ODBC .NET 410 What is a Data Service Component and Why Use it? 411 What is the Data Service Component? 411 What are the Benefits? 412 Creating a Data Service Component 413 The Data Service Component 413 The DataLayer Namespace – Public Enumerators 414 The ConfigSettings Class – Public Properties 415 The ConfigSettings Class – Public Constructors 416 The Commands Class – Public ExecuteQuery Method 418 The Commands Class – Public ExecuteNonQuery Method 422 The Commands Class – Private Connection Method 422 Creating an Assembly Information File 423 Compiling the Data Service Component 424 Deploying a Data Service Component 425 The Global Assembly Cache – (GAC) 425 Making a Reference to Wrox_DL in machine.config 428 Using the Data Service Component 428 Using in a ASP.NET Web Form 429 Executing SQL Text 429 Executing Stored Procedures 435 Using in a Web Service 438 [...]... disconnected recordsets, whereas ADO.NET has different classes for connected and disconnected access, and doesn't permit updateable connected recordsets We'll look at this issue in more detail later in the chapter Architectural Overview of ADO.NET Now that you're hopefully convinced of why you should use ADO.NET, we can look at how ADO.NET works in more detail The ADO.NET object model consists of two... are collectively known as ADO.NET In fact, NET programming is effectively programming with the NET class libraries –it's impossible to write any program in C# or VB NET that doesn't use these libraries 12 Data Access and NET Not Another Data Access Technology? Given the revolutionary nature of NET, and the fact that new class libraries have been introduced for almost every programming task, it's hardly... because many of the classes and concepts are similar, knowledge of ADO is a big advantage when learning ADO.NET We will look at the relationship between ADO and ADO.NET in more detail later on in the chapter First, though, let's take an overview of ADO.NET itself 14 Data Access and NET Introduction to ADO.NET Although we've presented it as something of an inevitability that NET would bring a new data... XML RAW Using FOR XML RAW with ADO.NET FOR XML AUTO FOR XML AUTO and ADO.NET FOR XML EXPLICIT 517 518 521 522 523 525 527 529 FOR XML EXPLICIT – Two-Level Example 531 Entity Encoding Directives FOR XML EXPLICIT – Three- Level Example 532 533 536 FOR XML EXPLICIT – ADO.NET FOR XML EXPLICIT – Conclusion 539 541 OPENXML OPENXML Stored Procedures: Deletion and Updates OPENXML ADO.NET: Insertion, Deletion,... overview of ADO.NET This will be fast-paced, and we won't shy away from showing snippets of code, as this really is the best way to get to grips with the concepts Hopefully t his chapter will give you a solid understanding of the basic workings of ADO.NET, and give you a taste of some of its best features By the end of the chapter, we hope that you'll be convinced of the advantages of ADO.NET, and... comes along every year or so However, it's not quite time to throw away all your existing knowledge – ODBC and OLE DB can both be used from ADO.NET, and it's going to be quite some time before ADO.NET can access any data source directly And even ADO, for which ADO.NET is a more -or-less direct replacement, can have its uses in certain scenarios It's therefore worth spending a moment reviewing the development... advantages of ADO.NET, and eager to go further into the book! ADO.NET is the latest in a long line of data access technologies released by Microsoft ADO.NET differs somewhat from the previous technologies, however, in that it comes as part of a whole new platform called the NET Framework This platform is set to revolutionize every area of development, and ADO.NET is just one aspect of that We'll therefore start... ADO in NET applications through COM interoperability However, there are some very good reasons why ADO wasn't really suited to the new programming environment We'll look quickly at some of the ways in which ADO.NET improves upon ADO called from NET, before looking at the ADO.NET architecture in more detail Advantages of Using Managed Classes Firstly, and most obviously, if we're using NET then COM interoperability... revolutionize all aspects of programming in the Microsoft world The benefits of this new platform will be felt in all areas of our code and in all types of application we develop The NET Framework is in itself a huge topic, and we can't cover every aspect in detail here, but since it's important to understand the basic principles behind NET before attempting any ADO.NET programming, we'll quickly review... but since it's important to understand the basic principles behind NET before attempting any ADO.NET programming, we'll quickly review the basics here For more information about programming in the NET environment, check out Professional NET Framework, ISBN 1-861005-56-3 Chapte r 1 The Common Language Runtime The foundation on which the NET Framework is built is the Common Language Runtime (CLR) The . Using ADO 2.x in .NET 34 Using ADO. NET 36 C# Example 36 Visual Basic .NET Example 36 JScript .NET Example 37 Managed C++ Example 38 J# Example 39 ADO. NET Events. Accessing ADO from .NET 590 Whether to Access ADO from .NET 590 Accessing ADO from .NET 591 Platform Invocation Services (PInvoke) 594 Migration 595 ADO Data

Ngày đăng: 10/12/2013, 14:15

Từ khóa liên quan

Tài liệu cùng người dùng

  • Đang cập nhật ...

Tài liệu liên quan