Skip to Main Content
Programming C#
book

Programming C#

by Jesse Liberty
July 2001
Intermediate to advanced content levelIntermediate to advanced
688 pages
16h 14m
English
O'Reilly Media, Inc.
Content preview from Programming C#

Using ADO Managed Providers

The previous example used one of the two managed providers currently available with ADO.NET: the SQL Managed Provider and ADO Managed. The SQL Managed Provider is optimized for SQL Server and is restricted to working with SQL Server databases. The more general solution is the ADO Managed Provider, which will connect to any OLE DB provider, including Access.

You can rewrite Example 14-1 to work with the Northwind database using Access rather than SQL Server with just a few small changes. First, you need to change the connection string:

string connectionString = 
    "provider=Microsoft.JET.OLEDB.4.0; "
    + "data source = c:\\nwind.mdb";

This query connects to the Northwind database on C drive. (Your exact path might be different.)

Next, change the DataAdapter object to an ADODataAdapter rather than a SqlDataAdapter:

OleDbDataAdapter DataAdapter = 
    new OleDbDataAdapter (commandString, connectionString);

Also be sure to add a using statement for the OleDb namespace:

using System.Data.OleDb;

This design pattern continues throughout the two Managed Providers; for every object whose class name begins with “Sql,” there is a corresponding class beginning with “ADO.” Example 14-2 illustrates the complete ADO version of Example 14-1.

Example 14-2. Using the ADO Managed Provider

using System;
using System.Drawing;
using System.Collections;
using System.ComponentModel;
using System.Windows.Forms;
using System.Data;
using System.Data.OleDb; namespace ProgrammingCSharpWinForm ...
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Start your free trial

You might also like

Programming C#, Second Edition

Programming C#, Second Edition

Jesse Liberty
Programming C# 12

Programming C# 12

Ian Griffiths
Programming C# 8.0

Programming C# 8.0

Ian Griffiths

Publisher Resources

ISBN: 0596001177Supplemental ContentCatalog PageErrata