Questions That Should Be Asked More Frequently

Part II

Getting Connected: Using a .NET Data Provider

Chapter 3

Connecting to Your Database

Part of building a database application requires that you connect to your data source and manage that connection. In the ADO.NET object model, the Connection object represents a connection to your data source.

This chapter will serve as your guide to the ADO.NET Connection object by covering the major features of the object. In the process, we'll learn how to create and use Connection objects both in code and through the Visual Studio .NET development environment.

Throughout the chapter, we'll focus on the more generic of the two Connection objects that reside in the Microsoft .NET Framework, the OleDbConnection object. Unless otherwise noted, the features of the object are generic and apply to all Connection objects regardless of their .NET Data Provider.

Code snippets assume that you have used the appropriate construct to reference the System.Data, System.Data.OleDb, and System.Data.SqlClient namespaces. The following lines of code (Visual Basic .NET and Visual C#. NET, respectively) must appear at the beginning of your code modules. For more information on these constructs, please see the documentation of your language of choice.

In Visual Basic .NET, the code would look like this:

Imports System.Data Imports System.Data.OleDb Imports System.Data.SqlClient

In Visual C#. NET, the code would look like this:

using System.Data; using System.Data.OleDb; using System.Data.SqlClient;



Microsoft ADO. NET Core Reference
Microsoft ADO.NET (Core Reference) (PRO-Developer)
ISBN: 0735614237
EAN: 2147483647
Year: 2002
Pages: 104
Authors: David Sceppa

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