.NET
  Home arrow .NET arrow Page 3 - The Provider Factory in ADO.NET 2.0
ASP Free Forums 
.NET  
ASP  
ASP Code  
ASP.NET  
ASP.NET Code  
BrainDump  
C#  
Code Examples  
Database  
Database Code  
IIS  
Microsoft Access  
MS SQL Server  
Visual Basic.NET  
Windows Scripting  
Windows Security  
XML  
ASP Web Hosting  
ASP.NET Web Hosting 
Dedicated Servers 
Moblin 
JMSL Numerical Library 
Windows Web Hosting
 
IBM® developerWorks 
Sun Developer Network 
Weekly Newsletter
 
Developer Updates  
Free Website Content 
 RSS  Articles
 RSS  Forums
 RSS  All Feeds
Write For Us Get Paid 
Request Media Kit
Contact Us 
Site Map 
Privacy Policy 
Support 
 USERNAME
 
 PASSWORD
 
 
  >>> SIGN UP!  
  Lost Password? 
.NET

The Provider Factory in ADO.NET 2.0
By: Jayaram Krishnaswamy
  • Search For More Articles!
  • Disclaimer
  • Author Terms
  • Rating: 3 stars3 stars3 stars3 stars3 stars / 7
    2006-08-09

    Table of Contents:
  • The Provider Factory in ADO.NET 2.0
  • Data Providers on This Machine
  • More Data Providers on This Machine
  • Creating Provider Independent Data Access

  • Rate this Article: Poor Best 
      ADD THIS ARTICLE TO:
      Del.ici.ous Digg
      Blink Simpy
      Google Spurl
      Y! MyWeb Furl
    Email Me Similar Content When Posted
    Add Developer Shed Article Feed To Your Site
    Email Article To Friend
    Print Version Of Article
    PDF Version Of Article
     
     
    ADVERTISEMENT


    The Provider Factory in ADO.NET 2.0 - More Data Providers on This Machine


    (Page 3 of 4 )

    System.Data.SqlClient.SqlClientFactory

    To find all the different providers on this machine the GetFactoryClasses must be interrogated. This method is described as follows (copied from the ObjectBrowser in VS 2005):

    GetFactoryClasses() As System.Data.DataTable

    Public Shared Function GetFactoryClasses() As System.Data.DataTable
    Member of: System.Data.Common.DbProviderFactories
    Summary:
    Returns a System.Data.DataTable that contains information about all 
    installed providers that implement System.Data.Common.DbProviderFactory. Return Values: Returns a System.Data.DataTable containing System.Data.DataRow objects
    that contain the following data. Column ordinalColumn nameDescription 0NameHuman-readable
    name for the data provider.1DescriptionHuman-readable description of the data provider.
    2InvariantNameName that can be used programmatically to refer to the data provider.
    3AssemblyQualifiedNameFully qualified name of the factory class, which contains enough information
    to instantiate the object.

    As the return value comes out in rows of data in three columns each, place a command button, a textbox and a GridView control on the form, and to the click event of the button insert the following code.

    Protected Sub Button1_Click(ByVal sender As Object, _
    ByVal e As System.EventArgs) Handles Button1.Click
    'since we know the returned info is in a table format we start out 
    'with a table
    Dim dtable As New DataTable
    'GetDataClasses() is without any arguments
    dtable = Data.Common.DbProviderFactories.GetFactoryClasses
    GridView1.DataSource = dtable
    GridView1.DataBind()
    GridView1.Visible = True
    Dim drfow As System.Data.Common.DbProviderFactory
    drfow = Data.Common.DbProviderFactories.GetFactory(dtable.Rows(1))
    TextBox2.Text = drfow.ToString
    End Sub
    

    When the button is clicked all the different providers are displayed in the GridView as shown in the next picture. The last two providers are not from an out-of-the box install of VS 2005. These were automatically added when Jasper (SQL Anywhere 10) was installed on this machine.

    The textbox shows the variable drfow in the following paragraph corresponding to the second row.

    System.Data.OleDb.OleDbFactory

    It was noted that, although the individual columns for any row should be accessible, the program throws an exception for any value other than for ColumnIndex=2 for no apparent reason.

    More .NET Articles
    More By Jayaram Krishnaswamy


       · Yes, that is true, more power with less coding. In an earlier tutorial,'Using the...
     

    .NET ARTICLES

    - More on Commands, Input and the WPF
    - Grouping and Aggregating When Querying LINQ ...
    - Commands, Input and the WPF
    - Keyboard and Ink Input with WPF
    - Mouse Input and the WPF
    - Input with Windows Presentation Foundation
    - Introducing LINQ with XML and Databases
    - An Introduction to LINQ
    - Querying LINQ to SQL: Basics
    - Completing a Simple Storefront with LINQ
    - Knowing Your Environment: the System.Environ...
    - Creating the Home Page for a Simple Storefro...
    - LINQ Quickly with Language Integrated Queries
    - Introducing LINQ to SQL Designer using Visua...
    - Beginning LINQ to SQL Using Visual Studio 20...





    © 2003-2008 by Developer Shed. All rights reserved. DS Cluster 6 hosted by Hostway