OleDbProvider : Data Provider « ADO.Net « C# / CSharp Tutorial






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

    class OleDbProvider
    {
        static void Main(string[] args)
        {
            string connString = @"provider = sqloledb;data source = .\sqlexpress;integrated security = sspi;initial catalog = northwind";
            string sql = @"select * from employees";
            OleDbConnection conn = null;
            OleDbDataReader reader = null;
            try
            {
                conn = new OleDbConnection(connString);
                conn.Open();
                OleDbCommand cmd = new OleDbCommand(sql, conn);
                reader = cmd.ExecuteReader();
                while (reader.Read())
                {
                    Console.WriteLine(
                       "{0} | {1}"
                     , reader["FirstName"].ToString().PadLeft(10)
                     , reader[1].ToString().PadLeft(10)
                    );
                }
            }
            catch (Exception e)
            {
                Console.WriteLine("Error: " + e);
            }
            finally
            {
                reader.Close();
                conn.Close();
            } 
        }
    }








32.31.Data Provider
32.31.1.Get the list of ADO.NET data providers registered in the machine and application configuration file
32.31.2.Create Database connection from DbProviderFactory
32.31.3.OleDbProvider