ADO.NET  Examples and Best Practices
for C# Programmers
by William R. Vaughn with Peter Blackburn

Apress: Books for Professionals by Professionals ®

Up

The Example Code

Throughout the book, you will find references to example code and utilities. All of this code can be found here on the CD. Feel free to grab any code snippet that you find useful and play with it, break it, put it in your application, etc. However, all code is provided on an "as-is" basis. This means it's not guaranteed in any way. See the license agreement that comes with the book. Here are a few tips to help you get started:

bullet You'll probably want to copy the contents of the CD to a local hard disk--not a shared directory on another system. That's because the .NET examples won't be "trusted" if they are not loaded from a local hard disk or other R/W media.
bullet For any of the ODBC examples, you will also need to create the LocalServer DSN. This DSN simply references the local (.) version of SQL Server.
bullet Some examples use resources not available in the CD; these are intended to showcase C# code rather than to "work out of the box."

See Setup Instructions for more detailed information about setting up the databases used by the examples.

Visual SourceSafe 6.0c  Archive File

On the CD in \Examples\VssArch Folder I have placed a Visual SourceSafe 6.0c archive of examples (VSSADOC#EBP.ssa). You should be able to restore this archive to a Visual SourceSafe Database - if you do, then you will be able to mess up the examples and assuming that you periodically check-in your changes you'll be able to historically see the steps you took to mess up the examples. However, you don't have to use Visual SourceSafe if you don't want to as I have also included the examples separately.

Chapter Referenced Example Code

In most chapters, examples will be provided to demonstrate the topic being discussed. These examples are referenced in the text by a footnote such as "Located in the "\Examples\Chapter 06\AddNew" folder on the CD."

To use these examples, simply load it from the local hard disk folder's ".sln" (solution) file using the Visual Studio .NET IDE.

Tip: If you encounter "protection" errors loading a project, remember that Visual Studio .NET requires that the files be loaded from a local hard disk--not from a shared network drive.
Chapter 1: Introducing ADO.NET
Data Adapter
Data Stream
Simple Fill Query
  
Chapter 2: ADO.NET--Getting Connected
ConnectionString Examples
ConnectionString Test
Dual Connection
Odbc Error Handler
ODBCTest
 
Chapter 3: Command Strategies
DACW Example
DataReader
Default Parm Values
ExecuteScalar
Multiple DataAdapter
Multiple Resultset
MultipleResultset SP NextRecordset
Parameter Constructors
Parameter Query
Perftest with TicCount
Simple SelectCommand
SP With Output Parms
SP With Output Parms ExecuteReader
StoredProc Query
VB Perftest with TicCount
 
Chapter 4: DataReader Strategies
DataReader GetValues
Fetch BLOB from DB
GetDataSchema method
LoadCovers
Chapter 5: Using the DataTable and DataSet
CreateDataTable
CreateRowsWithItemArray
Data RowState
DataColumn DataRow
DataRows
DataTable Fill Multiple Tables
DataTypesTest
Import ADOc Recordset (OleDB)
ItemArray
Multiple Fills
Naming Tables with Fill
Typed Dataset Construction
XSD Schema without VS
  
Chapter 6: Filtering, Sorting and Finding
DataView
DataView Find Array
Filter
Find method
Find Method SqlClient
Remove and Insert via Method
Simple Find
  
Chapter 7: ADO.NET Update Strategies
Command Builder
Create Author Update SPs
Data RowState
DataColumn DataRow
DAW Authors Example
DeriveParameters
Identity Value Via OUTPUT Parm
Remove and Insert via method
Update
 
Chapter 8: ADO.NET Constraint Strategies
Create UniqueConstraints
Customer Access1
FillSchema to build Constraints
ForeignKeyConstraint Example
UniqueIndex With Multiple Columns
 
Chapter 9: ADO.NET Error Management Strategies
OleDb Error Handling
SqlClient Error Handler
 
Chapter 10: ADO.NET and XML
BiblioServices
InfoRequest calls Web Service
UpdateInfoRequestService
XML From Web Service