日期:2014-05-16 浏览次数:20462 次
原文:http://www.cnblogs.com/wangzhq/archive/2006/09/14/504309.html#1744469
using System; using System.Collections.Generic; using System.Text; using System.Data; using System.Data.Common; using System.Configuration; using System.Collections; namespace Ths { /**//// <summary> ======================================================== /// /// wangzhq.cnblogs.com /// 数据工厂类,实现了跨数据库的操作. /// ======================================================== /// </summary> public class DataAccess:PageBase { /**//// <summary> /// Webconfig配置连接字符串 /// </summary> private string _confirString = "ConnectionString"; /**//// <summary> /// 数据工厂类 /// </summary> public DataAccess() { } /**//// <summary> /// 数据工厂类 /// </summary> /// <param name="configString">web.config 关键字</param> public DataAccess(string configString) { ConfigString = configString; } /**//// <summary> /// 属性,设置数据库连接字符串 /// </summary> public string ConfigString { get { return _confirString; } set { _confirString = value; } } //==============================================GetProviderName============================== 获得数据库的类型 public string GetProviderName(string ConfigString)#region 获得数据库的类型 public string GetProviderName(string ConfigString) /**//// <summary> /// 返回数据提供者 /// </summary> /// <returns>返回数据提供者</returns> public string GetProviderName(string ConfigString) { ConnectionStringSettingsCollection ConfigStringCollention = ConfigurationManager.ConnectionStrings; if (ConfigStringCollention == null || ConfigStringCollention.Count <= 0) { throw new Exception("web.config 中无连接字符串!"); } ConnectionStringSettings StringSettings = null; if (ConfigString == string.Empty) { StringSettings = ConfigurationManager.ConnectionStrings["ConnectionString"]; } else { StringSettings = ConfigurationManager.ConnectionStrings[ConfigString]; } return StringSettings.ProviderName; } /**//// <summary> /// 返回数据提供者 /// </summary> /// <returns></returns> public string GetProviderName() { return GetProviderName(ConfigString); } #endregion //=====================================================获得连接字符串==================================== /**//// <summary> /// 获得连接字符串 /// </summary> /// <returns></returns> public string GetConnectionString(string ConfigString) { ConnectionStringSettingsCollection ConfigStringCollention = ConfigurationManager.ConnectionStrings; if (ConfigStringCollention == null || ConfigStringCollention.Count <= 0) { throw new Exception("web.config 中无连接字符串!"); } ConnectionStringSettings StringSettings = null; if (ConfigString == string.Empty) { StringSettings = ConfigurationManager.ConnectionStrings["ConnectionString"]; } else { StringSettings = ConfigurationManager.ConnectionStrings[ConfigString]; } return StringSettings.ConnectionString; } public string GetConnectionString() { return GetConnectionString(Conf