ADO.NET Namespaces


ASP.NET Developer's JumpStart
By Paul D. Sheriff, Ken Getz
Table of Contents
Chapter 10.  Introduction to ADO.NET

The root namespace for working with data in the .NET Framework is System.Data. This namespace provides the DataSet and DataTable objects you'll use to work with any type of data. In addition, the .NET Framework provides two specific namespaces that each provides objects for retrieving data that you'll learn about in this book:

  • System.Data.OleDb. Used for working with any OLE DB data source, such as Jet, Oracle, and so on. This namespace supports existing unmanaged (that is, with code written outside the CLR) ADO providers. This namespace includes the OleDbConnection, OleDbCommand, OleDbDataReader, and OleDbDataAdapter objects.

  • System.Data.SqlClient. Provides direct support for SQL Server 6.5 and later, using a managed provider. If you know you'll be working only with SQL Server, you'll want to take advantage of the optimized behavior of this set of classes. This namespace includes the SqlConnection, SqlCommand, SqlDataReader, and SqlDataAdapter objects.

You can be relatively sure that Microsoft (and other vendors) will release additional assemblies (and namespaces) containing ADO.NET objects. For example, before the Visual Studio .NET shipped, Microsoft had already released the System.Data.ODBC namespace, and by the time you read this, it's likely that an Oracle-specific namespace will be available as well. (The Oracle namespace wasn't available at the time we wrote this book.) We'll focus on the OleDb and SqlClient namespaces throughout the rest of this book.

To get a copy of the System.Data.Odbc namespace, visit Microsoft's download site at Search for odbc, and you'll find this useful addition to the .NET Framework.

Visual Basic .NET adds an implicit Imports statement for System.Data to all your projects for you (unless you change this behavior in the Property Pages dialog box for your project). Although you could refer to ADO.NET objects like this, you can also abbreviate them, as the following code fragment shows:

 Dim da1 As System.Data.SqlClient.SqlDataAdapter ' This works fine, too Dim da2 As SqlClient.SqlDataAdapter 

If you're going to be using the System.Data.SqlClient namespace throughout your application, you might consider adding an Imports statement for the namespace at the top of each file that uses the objects, like this:

 ' Insert this at the top of a file: Imports System.Data.SqlClient ' Now this works, as well: Dim da3 As SqlDataAdapter 

You can use the same techniques when working with the System.Data.OleDb namespace as well.


    ASP. NET Developer's JumpStart
    ASP.NET Developers JumpStart
    ISBN: 0672323575
    EAN: 2147483647
    Year: 2002
    Pages: 234 © 2008-2017.
    If you may any questions please contact us: