DALHelper.cs
上传用户:simon2hong
上传日期:2021-11-18
资源大小:16746k
文件大小:3k
源码类别:

OA系统

开发平台:

C#

  1. //------------------------------------------------------------------------------
  2. // 创建标识: Copyright (C) 2009 蛋蛋 版权所有
  3. // 创建描述: 蛋蛋代码生成器 V4.3.2.3 自动创建于 2009-12-23 10:03:32
  4. //
  5. // 功能描述: 
  6. //
  7. // 修改标识: 
  8. // 修改描述: 
  9. //------------------------------------------------------------------------------
  10. using System;
  11. using System.Collections.Generic;
  12. using System.Text;
  13. using System.Configuration;
  14. using System.Collections;
  15. using System.IO;
  16. using System.Web;
  17. using DBUtility;
  18. namespace SqlServerDAL
  19. {
  20.     public class DALHelper
  21.     {
  22.         protected static DBHelper DataBaseOAHelper = GetHelper("DB");
  23.         /// <summary>
  24.         /// 从Web.config从读取数据库的连接以及数据库类型
  25.         /// </summary>
  26.         private static DBHelper GetHelper(string connectionStringName)
  27.         {
  28.             DBHelper dbHelper = new DBHelper();
  29.             // 从Web.config中读取数据库类型
  30.             string providerName = System.Configuration.ConfigurationManager.ConnectionStrings[connectionStringName].ProviderName;
  31.             switch (providerName)
  32.             {
  33.                 case "System.Data.OracleClient":
  34.                     dbHelper.DatabaseType = DBHelper.DatabaseTypes.Oracle;
  35.                     break;
  36.                 case "MySql.Data.MySqlClient":
  37.                     dbHelper.DatabaseType = DBHelper.DatabaseTypes.MySql;
  38.                     break;
  39.                 case "System.Data.OleDb":
  40.                     dbHelper.DatabaseType = DBHelper.DatabaseTypes.OleDb;
  41.                     break;
  42.                 case "System.Data.SqlClient":
  43.                 default:
  44.                     dbHelper.DatabaseType = DBHelper.DatabaseTypes.Sql;
  45.                     break;
  46.             }
  47.             // 从Web.config中读取数据库连接
  48.             switch (dbHelper.DatabaseType)
  49.             {
  50.                 case DBHelper.DatabaseTypes.OleDb:
  51.                     dbHelper.ConnectionString = "Provider=Microsoft.Jet.OLEDB.4.0;Persist Security Info=true;Data Source="
  52.                         + HttpContext.Current.Request.PhysicalApplicationPath
  53.                         + System.Configuration.ConfigurationManager.ConnectionStrings[connectionStringName].ConnectionString;
  54.                     break;
  55.                 default:
  56.                     dbHelper.ConnectionString = ConfigurationManager.ConnectionStrings[connectionStringName].ConnectionString;
  57.                     break;
  58.             }
  59.             return dbHelper;
  60.         }
  61.     }
  62. }