For creating objects using the common interface

Source: Internet
Author: User
Tags extend static class

Another benefit of using the generic interface is that it can be inherited to create a strongly typed DataSet. The benefits of a strongly typed dataset include design-time checks and visual Studio for strongly typed datasets. NET statement fill.

For the use of common interfaces is still more common, the use of dbproviderfactories and extended compatible MySQL I studied it in depth, let's take a look at it. Ado.net2.0 introduces a model of the provider factory and a common base class for various classes.

Ado. NET Common Interface Limitations: interfaces are not easy to extend, ado.net1.1 cannot create instances of certain classes, ado.net1.1 cannot determine the available. NET Data provider. Provides the factory model how to solve the above limitation, expands the ado,net model through the abstract accumulation.

Use the DbProviderFactories class to create an object. The limitations of the provider factory model, many query structures are unique to the database. When you set up CommandText for parameterized queries, you may need to provide program-specific code that specifies that the parameter data type may require a provider-specific code. In order to make the developed code generic.

Not limited to a specific database, this development decided to use dbproviderfactory+ standard SQL to develop a package for MySQL and SQL Server, but dbproviderfactories does not provide support for MySQL's dbproviderfactory, so it is necessary to extend Universal interface compatible with MySQL, and in Both MySQL and SQL Server's Parametermarkerformat are Bug,ado in 2.0. NET universal interface so the extended class is going to fix this bug.

public static Class Dbproviderfactoriesex


public static DbProviderFactory GetFactory (String providername)


if (providername = = null) throw new ArgumentNullException ("ProviderName");

DbProviderFactory dbfactory; Switch (providername)


Case "MySql.Data.MySqlClient": Return to New Mysqlclientfactory (); Default:return dbproviderfactories.getfactory (providername);



public static string Getparametermarkerformat (DbConnection Connect)


if (connect = null)

throw new ArgumentNullException ("Connect");

Type type = Connect. GetType ();

if (type = = typeof (MySql.Data.MySqlClient.MySqlConnection))

Return "? {0} ";//mysql bug

if (type = = typeof (System.Data.SqlClient.SqlConnection))

Return "@{0}";//ms Bug connect. Open ();

string result = Connect. GetSchema ("DataSourceInformation"). rows[0]["Parametermarkerformat"]. ToString ();

Connect. Close (); return result;



Related Article

E-Commerce Solutions

Leverage the same tools powering the Alibaba Ecosystem

Learn more >

Apsara Conference 2019

The Rise of Data Intelligence, September 25th - 27th, Hangzhou, China

Learn more >

Alibaba Cloud Free Trial

Learn and experience the power of Alibaba Cloud with a free trial worth $300-1200 USD

Learn more >

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: and provide relevant evidence. A staff member will contact you within 5 working days.