Skip to main content

2002 | Buch

ADO.NET Examples and Best Practices for C# Programmers

verfasst von: William R. Vaughn, Peter Blackburn

Verlag: Apress

insite
SUCHEN

Über dieses Buch

Written specifically for COM-based ADO developers retooling for ADO.NET using the C# language, this book brings fresh insights and tips on the ADO.NET technology. Veteran authors William Vaughn and Peter Blackburn have packed this formative guide with practical advice on how to write code that is both faster running and easier to understand.

The onset of the new .NET technology is forcing developers to completely rethink their data access strategies. This book helps you to do this through working examples and numerous discussions of what works and what doesnt. Derived from years of experience working with data access developers, ADO.NET Examples and Best Practices for C# Programmers includes a set of techniques proven to drastically reduce overhead, problems, and confusionfor the devleoper, the system, and the entire team. While some are quite simple to implement, others require considerable forethought to enable. This is a developers bookfull of hints, tips and notes passed on from those whove spent significant time in the .NET and C# trenches.

Inhaltsverzeichnis

Frontmatter
Chapter 1. Introducing ADO.NET
Abstract
This book is all about using ADO.NET with C# (pronounced C sharp),.NET Framework,’ and to some extent about how Visual Studio.NET helps you build ADO.NET-based applications. The concepts and code discussed and illustrated here apply (in most cases) to.NET Windows Forms and ASP Web Services and other ADO.NET platforms.
William R. Vaughn, Peter Blackburn
Chapter 2. ADO.NET—Getting Connected
Abstract
While it’s possible to create stand-alone data structures using ADO.NET without the benefit of a back-end data source—such as SQL Server, Access, Oracle, or other DBMS data sources—most developers must depend on ADO.NET and a database engine to construct objects reflecting the data and its schema. This chapter discusses how to establish a connection in .NET using three different .NET Data Providers as well as the “traditional” ADOc Connection object:
1.
Via the ADO.NET OleDb .NET Data Provider—System.Data.OleDb.
 
2.
Via the ADO.NET Tabular Data Stream (TDS) or SglClient .NET Data Provider—System. Data. SglClient.
 
3.
Via the ADO.NET Odbc .NET Data Provider—Microsoft.Data.Odbc
 
4.
Via ADOc. (Remember that ADOc refers to traditional COM-based ADO.)
 
William R. Vaughn, Peter Blackburn
Chapter 3. ADO.NET Command Strategies
Abstract
After you get your ADO.NET Connection1 object instantiated, you’re ready to start running queries. No, your code doesn’t necessarily have to explicitly open the connection to run a query, but you do need a well-written SQL SELECT statement. For the last twenty years, it’s been clear that improving poorly written queries plays a bigger role in best practice designs than any other single issue. The impact of a 100,000 row query on an ADO.NET application is no less serious than in an ADOc application. This chapter shows how to get Visual Studio to construct that optimal SQL query and pass it on to ADO.NET for execution.
William R. Vaughn, Peter Blackburn
Chapter 4. ADO.NET DataReader Strategies
Abstract
Ok, now that you’ve constructed a Command and executed a SELECT query you undoubtedly want to access the data returned. As with ADOc, ADO.NET can return data in a structure that contains both schema and data and additional metadata used to help in updating the data. You can also use lighter-weight (and faster) mechanisms that simply access the low-level data stream or a single value—that’s a DataReader, the subject of this chapter.
William R. Vaughn, Peter Blackburn
Chapter 5. Using the DataTable and DataSet
Abstract
We’ve come a long way toward learning about ADO.NET, but so far I’ve glossed over most of the details you need to understand ADO.NET’s newest concept: the DataSet. Well, it’s all new for ADOc developers. The ADO.NET DataSet is basically a collection of DataTable objects with a mechanism to tie the tables together rela­tionally and manage those tables as related sets of data. It also serves as a data source for bound controls. This means you won’t need a separate data source con­trol—such as an ADO Data Control—to bind resultsets to data-aware controls.
William R. Vaughn, Peter Blackburn
Chapter 6. Filtering, Sorting, and Finding
Abstract
As you saw in earlier chapters, ADO.NET supports a bevy of ways to manage the memory-resident data returned in a DataSet. In this section you’ll see that ADO.NET exposes additional functionality to the ways you can address, sort, filter, and find data—and for the first time, “select” data (well, in a way).
William R. Vaughn, Peter Blackburn
Chapter 7. ADO.NET Update Strategies
Abstract
Up to this point I’ve written a lot about extracting and massaging data from your data sources, but hardly a word about saving changes to the database or simply transporting the resultset data to some other tier. I expect that most of you work with applications where you need to change the data from time to time. This chapter focuses on the mechanics of persisting your changes to a data source or transporting your in-memory DataTable or DataRow data. Remember that ADO.NET is basically an “in-memory” data manager so “updating” might be as simple as changing the Value property in a DataRow; deleting a row could be implemented by using the RemoveAt method against the Rows collection. Updating might also be as complex as calling a series of conditional SQL queries that update a related set of tables applying complex business rules and triggers under a strict permissions regimen with convoluted referential integrity constraints.
William R. Vaughn, Peter Blackburn
Chapter 8. ADO.NET Constraint Strategies
Abstract
I just finished another long e-mail exchange with David Sceppa about some of the finer details of ADO.NET. I told him that I didn’t agree with some of the approaches Microsoft has taken toward handling data constraints, referential integrity, and data validation. He reminded me that developers don’t have to use them. That’s very true. IMHO, these features will be handy for a subset of the developers using ADO.NET—but not nearly all. This chapter discusses how ADO.NET has implemented referential and data constraints and also how to specify the relationships between tables in your database. I know, you’ve already done that and you’re wondering why ADO.NET doesn’t figure this out by itself. That’s a question I’m not prepared to answer.
William R. Vaughn, Peter Blackburn
Chapter 9. ADO.NET Exception Management Strategies
Abstract
One of the fundamental concepts you’ll encounter with the .NET Framework (regardless of the language you use) is how exceptions are exposed and managed. While the Visual Basic developer can still use the On Error GoTo syntax, it might not make much sense in light of how .NET exposes exceptions. Frankly, as long as On Error management evolves in Visual Basic .NET it remains moving target. Many fundamental On Error features were not implemented in the beta versions, which created quite a disturbance in the developer community. As a result (or so it seems), On Error handling has been almost completely restored. However, this chapter focuses on use of the try/catch exception handler. I also outline the various types of Exception classes you’re bound to trip as you work with ADO.NET.
William R. Vaughn, Peter Blackburn
Chapter 10. ADO.NET and XML
Abstract
Extensible Markup Language (XML) is the new1 universal format for data. XML allows developers to easily describe and deliver rich, structured data from any application in a standard, consistent way. XML does not replace HTML; rather, it is a complementary format. Microsoft is heavily investing in XML—you’ll see XML in versions of SQL Server 2000 and in many of Microsoft’s new applications. But, it’s clear that XML has not stopped its evolutionary process. The “original” form of XML used in ADOc is no longer used in ADO.NET and I expect further changes as the international standards committees tune and refine XML and its ancillary extensions, such as XSD and XSLT.
William R. Vaughn, Peter Blackburn
Backmatter
Metadaten
Titel
ADO.NET Examples and Best Practices for C# Programmers
verfasst von
William R. Vaughn
Peter Blackburn
Copyright-Jahr
2002
Verlag
Apress
Electronic ISBN
978-1-4302-1099-3
Print ISBN
978-1-59059-012-6
DOI
https://doi.org/10.1007/978-1-4302-1099-3