自拍偷在线精品自拍偷,亚洲欧美中文日韩v在线观看不卡

對于使用ADO.NET通用接口創(chuàng)建對象

開發(fā) 后端
使用ADO.NET通用接口的另一個好處是它能被繼承用于建立強類型的DataSet。強類型DataSet的好處包括設計時的檢查和強類型DataSet 的Visual Studio .NET語句填充。

對于ADO.NET通用接口的相關使用還是比較常見,就使用ADO.NET DbProviderFactories并擴充兼容mysql我深入的研究了一下,我們現(xiàn)在一起來看看吧。ADO.NET2.0 為各種ADO.NET類引入了一個提供程序工廠的模型以及通用基類。

ADO.NET通用接口的限制:接口不易擴展,ADO.NET1.1無法創(chuàng)建某些類的實例,ADO.NET1.1無法判斷可用的.NET數(shù)據(jù)提供程序。提供工廠模型如何解決上述限制,通過抽象積累來擴展ADO,NET模型。#t#

使用ADO.NET DbProviderFactories類來創(chuàng)建對象。提供程序工廠模型的限制,許多查詢結構都是數(shù)據(jù)庫特有的。為參數(shù)化查詢設置CommandText時,可能需要提供程序特有的代碼,指定參數(shù)數(shù)據(jù)類型可能需要提供程序特有的代碼。為了使開發(fā)的代碼通用。

不局限于特定的數(shù)據(jù)庫,本次開發(fā)中決定使用DbProviderFactory+標準SQL,以開發(fā)一個適用于mysql和 sqlserver的封裝,但DbProviderFactories 并沒有提供對mysql的DbProviderFactory的支持,所以需要擴充ADO.NET通用接口兼容mysql,而且在ADO.net 2.0中mysql和sqlserver的ParameterMarkerFormat都有bug,ADO.NET通用接口所以擴展類要解決這個bug。

  1. public static class DbProviderFactoriesEx  { 
  2.  public static DbProviderFactory GetFactory(string providerName)  { 
  3.  if (providerName == null)  throw new ArgumentNullException("providerName");  
  4. DbProviderFactory dbFactory;  switch (providerName) 
  5.  {  case "MySql.Data.MySqlClient":  return new MySqlClientFactory(); 
  6.  default:  return DbProviderFactories.GetFactory(providerName);  }  } 
  7.  public static string GetParameterMarkerFormat(DbConnection connect) 
  8.  {  if (connect == null)  throw new ArgumentNullException("connect"); 
  9.  Type type = connect.GetType();  if (type == typeof(MySql.Data.MySqlClient.MySqlConnection))
  10.   return "?{0}";//mysql bug  if (type == typeof(System.Data.SqlClient.SqlConnection)) 
  11.  return "@{0}";//ms bug  connect.Open();  string result = connect.GetSchema("DataSourceInformation").Rows[0]["ParameterMarkerFormat"].ToString();  
  12. connect.Close();  returresult;  }  }  
責任編輯:chenqingxiang 來源: CSDN
相關推薦

2009-12-21 16:53:06

ADO.NET使用說明

2009-12-21 17:35:24

ADO.NET對象

2009-12-23 14:07:09

ADO.NET實例對象

2009-12-21 14:39:09

ADO.NET技巧

2010-01-04 10:14:04

ADO.NET對象模型

2009-11-04 09:18:12

ADO.NET _Re

2009-12-23 09:32:26

ADO.NET數(shù)據(jù)對象

2009-11-13 14:38:45

ADO.NET Dat

2009-12-25 10:25:59

2009-12-18 13:52:39

ADO.NET設計器

2009-11-04 09:02:34

ADO.NET _C

2009-12-18 17:06:37

ADO.NET 數(shù)據(jù)庫

2009-10-29 13:34:01

ADO.NET對象

2009-12-23 17:54:01

ADO.NET 2.0

2009-12-23 16:43:34

ADO.NET模型

2009-11-04 12:45:33

ADO.NET Dat

2009-12-23 16:05:47

ADO.NET錯誤

2009-12-23 14:59:32

ADO.NET 2.0

2009-12-28 15:11:36

ADO.NET專家

2009-12-21 14:55:49

ADO.NET對象
點贊
收藏

51CTO技術棧公眾號