| About the Author |
|
xv | |
| About the Technical Reviewers |
|
xvii | |
| Acknowledgments |
|
xix | |
| Introduction |
|
xxi | |
|
An Introduction to ADO.NET |
|
|
1 | (14) |
|
|
|
2 | (1) |
|
|
|
3 | (1) |
|
Meeting the Players: Important Objects in ADO.NET |
|
|
4 | (3) |
|
|
|
4 | (1) |
|
|
|
5 | (2) |
|
|
|
7 | (7) |
|
Using the ProviderBase Model |
|
|
9 | (3) |
|
Third-Party .NET Data Providers |
|
|
12 | (2) |
|
The System.Data.Design Namespace |
|
|
14 | (1) |
|
|
|
14 | (1) |
|
|
|
15 | (16) |
|
This Is a Reference Chapter |
|
|
15 | (1) |
|
10,000-Ft. View of ADO.NET |
|
|
16 | (1) |
|
Establishing a Connection: DbConnection |
|
|
17 | (2) |
|
Executing a Command: DbCommand and DbTransaction |
|
|
19 | (3) |
|
Creating Parameterized Commands: DbParameter |
|
|
20 | (2) |
|
Holding Disconnected Data: DataSet |
|
|
22 | (2) |
|
Fetching Data: Data Reader and Data Adapter |
|
|
24 | (2) |
|
The Connected Way to Fetch Data: DbDataReader |
|
|
24 | (1) |
|
The Bridge Between Connected and Disconnected: DbDataAdapter |
|
|
25 | (1) |
|
|
|
26 | (4) |
|
|
|
30 | (1) |
|
|
|
31 | (22) |
|
Setting Up the Hello World Data Source |
|
|
31 | (1) |
|
Creating a Data-Driven Application: The Drag-and-Drop Approach |
|
|
32 | (13) |
|
Drag and Drop in ASP.NET 2.0 |
|
|
33 | (6) |
|
Drag and Drop in a Windows Forms Application |
|
|
39 | (6) |
|
Hybrid Approach: Write Some Code, Do Some Drag and Drop |
|
|
45 | (3) |
|
Data-Driven Application: The ``Write Code Yourself'' Approach |
|
|
48 | (3) |
|
|
|
51 | (2) |
|
Connecting to a Data Source |
|
|
53 | (24) |
|
|
|
53 | (13) |
|
Creating Connection Objects |
|
|
54 | (3) |
|
Generating Provider-Specific Connection Strings |
|
|
57 | (3) |
|
The Easy Way to Any Connection String |
|
|
60 | (2) |
|
Securing Connection Strings |
|
|
62 | (4) |
|
The Common Behavior: IDbConnection |
|
|
66 | (2) |
|
The Common Logic: DbConnection |
|
|
68 | (1) |
|
|
|
68 | (1) |
|
|
|
69 | (5) |
|
|
|
71 | (1) |
|
Deciding on the Right Pool Size |
|
|
72 | (1) |
|
|
|
73 | (1) |
|
Closing Connections: Good Application Design |
|
|
74 | (1) |
|
|
|
75 | (2) |
|
Retrieving Data in a Connected Fashion |
|
|
77 | (32) |
|
Communicating with the Data Source |
|
|
77 | (1) |
|
Retrieving a Scalar Value |
|
|
78 | (5) |
|
Which Database to Execute Against |
|
|
79 | (2) |
|
|
|
81 | (1) |
|
Executing a Command to Retrieve Results |
|
|
82 | (1) |
|
|
|
83 | (5) |
|
Querying a Result Set for Storage |
|
|
88 | (3) |
|
Querying Large Result Sets Asynchronously |
|
|
91 | (5) |
|
Querying the Database for Multiple Result Sets |
|
|
96 | (3) |
|
Object-Oriented vs. Relational Representation |
|
|
99 | (8) |
|
Storing Objects in the Database |
|
|
100 | (5) |
|
Querying for UDT Data Using SQL |
|
|
105 | (1) |
|
Retrieving UDT Data in a Connected Fashion |
|
|
105 | (1) |
|
|
|
106 | (1) |
|
|
|
107 | (2) |
|
|
|
109 | (68) |
|
The Case for the Disconnected Model |
|
|
109 | (2) |
|
|
|
111 | (14) |
|
|
|
112 | (1) |
|
|
|
113 | (1) |
|
|
|
114 | (1) |
|
|
|
115 | (1) |
|
Setting a Primary Key: PrimaryKey Property |
|
|
116 | (1) |
|
Dynamically Constructing a DataTable |
|
|
116 | (4) |
|
|
|
120 | (1) |
|
Practical Usage of DataTable Events |
|
|
121 | (4) |
|
|
|
125 | (3) |
|
|
|
125 | (3) |
|
|
|
128 | (6) |
|
DataSets As Data Transfer Objects |
|
|
134 | (6) |
|
Strongly Typed DataSets: An Introduction |
|
|
140 | (34) |
|
|
|
141 | (10) |
|
|
|
151 | (8) |
|
Building Strongly Typed DataSets |
|
|
159 | (9) |
|
Typed DataSet Performance |
|
|
168 | (1) |
|
Annotating Typed DataSets |
|
|
168 | (6) |
|
|
|
174 | (3) |
|
Fetching Data: The DataAdapter |
|
|
177 | (36) |
|
|
|
177 | (2) |
|
Structure of a DataAdapter |
|
|
178 | (1) |
|
Putting DataAdapters to Use |
|
|
179 | (25) |
|
Setting Up the Data Source |
|
|
179 | (1) |
|
Querying One Table: Point and Click |
|
|
180 | (5) |
|
Querying One Table: Writing Code |
|
|
185 | (5) |
|
Filling DataSets: More Than One Table |
|
|
190 | (6) |
|
|
|
196 | (8) |
|
|
|
204 | (8) |
|
|
|
204 | (2) |
|
The ADO.NET Mapping Mechanism |
|
|
206 | (6) |
|
|
|
212 | (1) |
|
Sorting, Searching, and Filtering |
|
|
213 | (34) |
|
Setting Up the Data Source |
|
|
214 | (2) |
|
|
|
216 | (10) |
|
|
|
217 | (2) |
|
Selecting a Number of Rows |
|
|
219 | (3) |
|
Expressions: Calculating Columns on the Fly |
|
|
222 | (2) |
|
Performing Aggregate Calculations |
|
|
224 | (2) |
|
Working with the DataRelation Object |
|
|
226 | (6) |
|
Working with the DataView Object |
|
|
232 | (8) |
|
|
|
232 | (8) |
|
Leveraging XML to Work with Disconnected Data |
|
|
240 | (5) |
|
|
|
241 | (4) |
|
|
|
245 | (2) |
|
|
|
247 | (74) |
|
Updating a Table: The Easy Drag-and-Drop Approach |
|
|
248 | (14) |
|
|
|
254 | (8) |
|
Using the Command Builder Object |
|
|
262 | (4) |
|
State Management in a DataRow and Its Use in Updating Data |
|
|
266 | (10) |
|
Moving Large Amounts of Data: SqlBulkCopy |
|
|
276 | (2) |
|
Editing Disconnected Data |
|
|
278 | (5) |
|
|
|
278 | (1) |
|
|
|
279 | (2) |
|
|
|
281 | (2) |
|
|
|
283 | (11) |
|
Writing This Application in Oracle |
|
|
293 | (1) |
|
Optimizing Your Application: GetChanges and Merge |
|
|
294 | (17) |
|
Merge Case 1: Same Table Structures, No Primary Key |
|
|
302 | (1) |
|
Merge Case 2: Same Table Structures, with Primary Key |
|
|
303 | (2) |
|
Merge Case 3: Common Column, No Primary Key |
|
|
305 | (1) |
|
Merge Case 4: Common Column, with Primary Key |
|
|
306 | (2) |
|
Merge Case 5: Absolutely Different Table Structures |
|
|
308 | (2) |
|
Merging Two DataSets/DataTables with Different Schemas |
|
|
310 | (1) |
|
Updating Records Using Mapped Names |
|
|
311 | (8) |
|
|
|
319 | (2) |
|
Updating Data: Advanced Scenarios |
|
|
321 | (34) |
|
Conflict Detection and Concurrency Resolution |
|
|
322 | (9) |
|
Preventing Conflicts: Traffic Lights |
|
|
322 | (1) |
|
Handling Conflicts: Going to the Hospital After an Accident |
|
|
323 | (8) |
|
Implementing Concurrency: Practical Concerns |
|
|
331 | (3) |
|
|
|
331 | (1) |
|
Number of Rows Affected and Triggers |
|
|
332 | (1) |
|
Multiple Rows Being Updated |
|
|
333 | (1) |
|
Working with Hierarchical Data |
|
|
334 | (18) |
|
Inserting Hierarchical Data |
|
|
338 | (9) |
|
Updating Hierarchical Data |
|
|
347 | (1) |
|
Deleting Hierarchical Data |
|
|
347 | (1) |
|
Putting It All Together: Saving Hierarchical Data |
|
|
347 | (4) |
|
This Code Just Won't Work! |
|
|
351 | (1) |
|
Hierarchical Updates: Conclusion |
|
|
352 | (1) |
|
|
|
352 | (3) |
|
|
|
355 | (58) |
|
|
|
356 | (3) |
|
|
|
356 | (1) |
|
|
|
357 | (1) |
|
|
|
358 | (1) |
|
ADO.NET Transaction Support |
|
|
359 | (4) |
|
|
|
361 | (2) |
|
Writing Transactional Database Applications |
|
|
363 | (22) |
|
Implementing Transactions |
|
|
363 | (7) |
|
Examining the Effect of Isolation Levels |
|
|
370 | (8) |
|
Multiple Active Resultsets |
|
|
378 | (4) |
|
|
|
382 | (3) |
|
Advanced Single Database Techniques |
|
|
385 | (7) |
|
|
|
386 | (3) |
|
|
|
389 | (1) |
|
Using Transactions with a DataSet and Data Adapter |
|
|
389 | (3) |
|
|
|
392 | (16) |
|
Important Players in Distributed Transactions: RMs and DTCs |
|
|
392 | (1) |
|
|
|
393 | (1) |
|
Implementing a Distributed Transaction: The .NET 1.1 Way |
|
|
393 | (4) |
|
Implementing a Distributed Transaction: The .NET 2.0 Way |
|
|
397 | (4) |
|
Promotable Enlistment: A Quick Primer |
|
|
401 | (2) |
|
System.Transactions: Manually Enlisting and Multithreaded Environments |
|
|
403 | (5) |
|
Judicious Use of Transactions |
|
|
408 | (3) |
|
Transactions and Performance |
|
|
409 | (1) |
|
Default Behavior for Transactions |
|
|
410 | (1) |
|
Transactions and User Confirmation |
|
|
410 | (1) |
|
Simultaneous ADO.NET and RDBMS Transactions |
|
|
410 | (1) |
|
|
|
411 | (2) |
|
|
|
413 | (47) |
|
SQL Server Native XML Support |
|
|
413 | (2) |
|
|
|
415 | (22) |
|
FOR XML Queries: A Quick Overview |
|
|
415 | (4) |
|
FOR XML's Optional Arguments |
|
|
419 | (1) |
|
|
|
420 | (1) |
|
|
|
420 | (2) |
|
|
|
422 | (11) |
|
SQL Server 2005 and FOR XML PATH |
|
|
433 | (1) |
|
Using FOR XML Queries with ADO.NET |
|
|
434 | (3) |
|
|
|
437 | (6) |
|
OPENXML Stored Procedures: Deletes and Updates |
|
|
440 | (3) |
|
The XML DataType: SQL Server 2005 Only |
|
|
443 | (3) |
|
Reading XML Columns in ADO.NET |
|
|
444 | (2) |
|
Working with SQL Server XML Features: SQLXML |
|
|
446 | (13) |
|
|
|
447 | (1) |
|
|
|
447 | (12) |
|
|
|
459 | (1) |
|
|
|
460 | (53) |
|
Appropriate Use of SQLCLR |
|
|
462 | (3) |
|
SQLCLR in Comparison with Extended Stored Procedures |
|
|
464 | (1) |
|
Software Requirements to Run the Examples in This Chapter |
|
|
465 | (1) |
|
|
|
465 | (3) |
|
|
|
468 | (4) |
|
|
|
472 | (3) |
|
Writing a TVF: Table-Valued Function |
|
|
475 | (12) |
|
Enumerating Files in a Directory Using a TVF |
|
|
485 | (2) |
|
Creating Aggregate Functions |
|
|
487 | (7) |
|
Writing a SQLCLR Stored Procedure |
|
|
494 | (10) |
|
|
|
494 | (10) |
|
|
|
504 | (1) |
|
Using Transactions in SQLCLR Triggers |
|
|
504 | (4) |
|
Using Non-Context Connections Inside SQLCLR |
|
|
508 | (3) |
|
|
|
511 | (2) |
|
|
|
513 | (16) |
|
Know Your System Requirements |
|
|
513 | (1) |
|
Picking the Right Tool for the Right Job |
|
|
514 | (8) |
|
Data Reader or DataSet/Data Adapter? |
|
|
515 | (2) |
|
DataSet or Strongly Typed DataSets |
|
|
517 | (1) |
|
Strongly Typed or Not? DataSet vs. Business Object |
|
|
517 | (3) |
|
T-SQL vs. SQLCLR vs. Extended Stored Procedures (XP) |
|
|
520 | (1) |
|
Transactions, Transactions Everywhere: Which Transaction to Pick |
|
|
521 | (1) |
|
Picking the Right Tools: The Clearly Darker Shades of Gray |
|
|
522 | (4) |
|
Implementing a Data Layer |
|
|
523 | (1) |
|
|
|
523 | (1) |
|
|
|
524 | (1) |
|
Complicated Hierarchical DataSets |
|
|
525 | (1) |
|
|
|
526 | (1) |
|
|
|
526 | (3) |
| Index |
|
529 | |