纽威
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

76 lines
2.4 KiB

3 years ago
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Data.Common;
  4. using System.Data.SqlClient;
  5. using System.Linq;
  6. using System.Text;
  7. using System.Threading.Tasks;
  8. using static ICSSoft.Common.DBHelper;
  9. namespace ICSSoft.Common
  10. {
  11. public class DbFactory
  12. {
  13. /// <summary>
  14. /// 根据配置文件中所配置的数据库类型
  15. /// 来获取命令参数中的参数符号oracle为":",sqlserver为"@"
  16. /// </summary>
  17. /// <returns></returns>
  18. public static string CreateDbParmCharacter()
  19. {
  20. string character = string.Empty;
  21. switch (DBHelper.DbType)
  22. {
  23. case DatabaseType.SqlServer:
  24. character = "@";
  25. break;
  26. case DatabaseType.Oracle:
  27. character = ":";
  28. break;
  29. case DatabaseType.MySql:
  30. character = "?";
  31. break;
  32. case DatabaseType.Access:
  33. character = "@";
  34. break;
  35. case DatabaseType.SQLite:
  36. character = "@";
  37. break;
  38. default:
  39. throw new Exception("数据库类型目前不支持!");
  40. }
  41. return character;
  42. }
  43. /// <summary>
  44. /// 根据配置文件中所配置的数据库类型
  45. /// 来创建相应数据库命令对象
  46. /// </summary>
  47. /// <returns></returns>
  48. public static DbCommand CreateDbCommand()
  49. {
  50. DbCommand cmd = null;
  51. switch (DBHelper.DbType)
  52. {
  53. case DatabaseType.SqlServer:
  54. cmd = new SqlCommand();
  55. break;
  56. //case DatabaseType.Oracle:
  57. // cmd = new OracleCommand();
  58. // break;
  59. //case DatabaseType.MySql:
  60. // cmd = new MySqlCommand();
  61. // break;
  62. //case DatabaseType.Access:
  63. // cmd = new OleDbCommand();
  64. // break;
  65. //case DatabaseType.SQLite:
  66. // cmd = new SQLiteCommand();
  67. // break;
  68. default:
  69. throw new Exception("数据库类型目前不支持!");
  70. }
  71. return cmd;
  72. }
  73. }
  74. }