Chapter 13. Programming with ADO.NET

Team-Fly    

 
Application Development Using Visual Basic and .NET
By Robert J. Oberg, Peter Thorsteinson, Dana L. Wyatt
Table of Contents
Part 6.  .NET Applications


The .NET Framework database programming classes are referred to as ADO.NET. ADO.NET introduces the DataSet class that works with relational data in a relational manner while you are disconnected from any data source. You need not connect and update or query the database unless you have a specific reason for doing so. You can, of course, work in the traditional connected manner if you choose.

ADO.NET data providers [1] allow you to execute commands directly against the data source. Functionality is exposed directly without intermediary objects such as OLE DB, which stands between ADO and the data source. The .NET DataAdapter class models a data source as a set of database commands and a connection to that data source. Differences between data sources are not hidden by generic interfaces. The OLE DB data provider allows for nested transactions with data sources that support that functionality; the SQL Server data provider does not. [2]

[1] .NET data providers are what used to be called in the beta literature managed providers . You may still see them referred to by that term .

[2] There is a Begin method on the OleDbTransaction class; the SqlTransaction class does not have such a method.

.NET data providers supply data to a dataset or a data reader. A dataset is a memory-resident, lightweight relational database that is not connected to any database. You can also obtain a dataset from an XML document or create an XML document from a dataset. This allows you to work, if it makes sense, with your data as relational data or as hierarchical XML data. [3] Data readers model the traditional method of working with a database.

[3] The many-to-many relations that you can have in a relational database do not automatically map to XML hierarchies. But this is no different from working with the classic object-relational model clash .

The data access classes that currently ship with the framework are found in the namespaces: System.Data , System.Data.SqlClient , System.Data.OleDb , System.Data.Common , and System.Data.SqlTypes . The SqlClient and OleDb namespaces reflect the SQL Server and OLE DB .NET data providers. An ODBC .NET data provider has been written, and additional ones will be written in the future.

This chapter changes the implementation of the Customer and Hotel assemblies of the case study to use SQL Server. An air travel service that the Acme Travel Agency can use to make air travel reservations is added to illustrate the use of XML. There is also a small database introduced for use by a travel agency, which offers travel services to its clients through hotel and airline brokers .

To make our examples concrete, we use SQL Server 2000 and the SQL Server data provider. [4] Nonetheless, much of the basic functionality discussed in this chapter applies to the OLE DB data provider as well, which we illustrate with an Access version of one of our databases.

[4] If you do not have a SQL Server available, you can go to the Microsoft Web site and download the MSDE, which is a scaled-down version of SQL Server. As of this writing MSDE is available for free to owners of Visual Studio. As its name suggests, MSDE is a database "engine" and does not come with any development tools, such as Enterprise Manager and Query Manager. Microsoft suggests using SQL Server Developer Edition for development. Despite the lack of developer tools, you may be able to make do with MSDE by using Visual Studio's Server Explorer. We illustrate use of Server Explorer in this chapter.

This chapter assumes you have some understanding of database concepts.

Setting Up the Example Databases

This chapter assumes that SQL Server 2000 has been installed using the Local System account, with authentication mode set to Mixed Mode. The user is assumed to be sa, with a blank password.

Several examples in this chapter make use of the Northwind Traders sample database, which is installed along with SQL Server. In addition, there are other example programs that use the AcmeCustomer, HotelBroker, and AirlineBroker databases, which are supplied specifically for use with this book.

Some of the example programs make changes to these databases, and other examples assume a freshly installed database. This means that some of the examples will not always work as expected unless you reinstall them. You can reinstall each of these databases by running the SQL scripts that are provided.

Please refer to the readme.txt file in the sample code directory for this chapter for more information about database setup.


Team-Fly    
Top
 


Application Development Using Visual BasicR and .NET
Application Development Using Visual BasicR and .NET
ISBN: N/A
EAN: N/A
Year: 2002
Pages: 190

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net