The C# Station ADO.NET Tutorial
Table of contents
Lesson 01: Introduction to ADO.NET
Lesson 02: The SqlConnection Object
Lesson 03: The SqlCommand Object
Lesson 04: Reading Data with the SqlDataReader
Lesson 05: Working with Disconnected Data
Lesson 06: Adding Parameters to Commands
Lesson 07: Using Stored Procedures
Lesson 01: Introduction to ADO.NET This lesson is an introduction to ADO.NET. It introduces primary ADO.NET concepts and objects that you will learn about in later lessons. Here are the objectives of this lesson: • • • • • • •
Learn what ADO.NET is. Understand what a data provider is. Understand what a connection object is. Understand what a command object is. Understand what a DataReader object is. Understand what a DataSet object is. Understand what a DataAdapter object is.
Introduction ADO.NET is an object-oriented set of libraries that allows you to interact with data sources. Commonly, the data source is a database, but it could also be a text file, an Excel spreadsheet, or an XML file. For the purposes of this tutorial, we will look at ADO.NET as a way to interact with a data base. As you are probably aware, there are many different types of databases available. For example, there is Microsoft SQL Server, Microsoft Access, Oracle, Borland Interbase, and IBM DB2, just to name a few. To further refine the scope of this tutorial, all of the examples will use SQL Server. You can download the Microsoft SQL Server 2000 Desktop Engine (MSDE 2000) here: http://www.microsoft.com/sql/msde/downloads/download.asp MSDE contains documentation on how to perform an installation. However, for your convenience, here are quick instructions on how to install MSDE: http://www.asp.net/msde/default.aspx?tabindex=0&tabid=1 MSDE 2000 is a scaled down version of SQL Server. Therefore, everything you learn in this tutorial and all code will work with SQL Server. The examples will use the Northwind database. This is a tutorial is specifically for ADO.NET. MSDE is not part of ADO.NET, but it is one of the many data sources you can interact with by using ADO.NET If you need help with MSDE 2000, I refer you to the Microsoft Web site, where you can find pertinent information on licensing and technical assistance: http://www.microsoft.com/sql/msde/
Data Providers We know that ADO.NET allows us to interact with different types of data sources and different types of databases. However, there isn't a single set of classes that allow you to accomplish this universally. Since different data sources expose different protocols, we need a way to communicate with the right data source using the right protocol. Some older data sources use the ODBC protocol, many newer data sources use the OleDb protocol, and there are more data sources every day that allow you to communicate with them directly through .NET ADO.NET class libraries. ADO.NET provides a relatively common way to interact with data sources, but comes in different sets of libraries for each way you can talk to a data source. These libraries are called Data Providers and are usually named for the protocol or data source type they allow you to interact with. Table 1 lists some well known data providers, the API prefix they use, and the type of data source they allow you to interact with. Table 1. ADO.NET Data Providers are class libraries that allow a common way to interact with specific data sources or protocols. The library APIs have prefixes that indicate which provider they support.
Provider Name ODBC Data Provider OleDb Data Provider Oracle Data Provider SQL Data Provider Borland Data Provider
API Data Source Description prefix Data Sources with an ODBC interface. Normally older data Odbc bases. Data Sources that expose an OleDb interface, i.e. Access or OleDb Excel. Oracle For Oracle Databases. Sql Bdp For interacting with Microsoft SQL Server. Generic access to many databases such as...
Please join StudyMode to read the full document