using System; using System.Collections.Generic; using System.Data.Common; using System.Data.SqlClient; using System.Linq; using System.Text; using System.Threading.Tasks; using static ICSSoft.Common.DBHelper; namespace ICSSoft.Common { public class DbFactory { /// /// 根据配置文件中所配置的数据库类型 /// 来获取命令参数中的参数符号oracle为":",sqlserver为"@" /// /// public static string CreateDbParmCharacter() { string character = string.Empty; switch (DBHelper.DbType) { case DatabaseType.SqlServer: character = "@"; break; case DatabaseType.Oracle: character = ":"; break; case DatabaseType.MySql: character = "?"; break; case DatabaseType.Access: character = "@"; break; case DatabaseType.SQLite: character = "@"; break; default: throw new Exception("数据库类型目前不支持!"); } return character; } /// /// 根据配置文件中所配置的数据库类型 /// 来创建相应数据库命令对象 /// /// public static DbCommand CreateDbCommand() { DbCommand cmd = null; switch (DBHelper.DbType) { case DatabaseType.SqlServer: cmd = new SqlCommand(); break; //case DatabaseType.Oracle: // cmd = new OracleCommand(); // break; //case DatabaseType.MySql: // cmd = new MySqlCommand(); // break; //case DatabaseType.Access: // cmd = new OleDbCommand(); // break; //case DatabaseType.SQLite: // cmd = new SQLiteCommand(); // break; default: throw new Exception("数据库类型目前不支持!"); } return cmd; } } }