/// <summary> /// 建立Sql命令 /// </summary> /// <param name="type"></param> /// <returns></returns> public static IDbCommand CreateDbCommand(DateBaseType type) { IDbCommand cmd = null; switch (type) { case DateBaseType.ORACLE: cmd = new OracleCommand(); break; case DateBaseType.SQLSERVER: cmd = new SqlCommand(); break; case DateBaseType.MYSQL: cmd = new MySqlCommand(); break; case DateBaseType.ACCESS: cmd = new OleDbCommand(); break; case DateBaseType.SQLLITE: cmd = new SQLiteCommand(); break; case DateBaseType.NONE: throw new Exception("未设置数据库类型"); default: throw new Exception("不支持该数据库类型"); } return(cmd); }
/// <summary> /// 建立SQL连接 /// </summary> /// <param name="type"></param> /// <param name="connectionString"></param> /// <returns></returns> public static IDbConnection CreateDbConnection(DateBaseType type, string connectionString) { IDbConnection conn = null; switch (type) { case DateBaseType.ORACLE: conn = new OracleConnection(connectionString); break; case DateBaseType.SQLSERVER: conn = new SqlConnection(connectionString); break; case DateBaseType.MYSQL: conn = new MySqlConnection(connectionString); break; case DateBaseType.ACCESS: conn = new OleDbConnection(connectionString); break; case DateBaseType.SQLLITE: conn = new SQLiteConnection(connectionString); break; case DateBaseType.NONE: throw new Exception("未设置数据库类型"); default: throw new Exception("不支持该数据库类型"); } return(conn); }
/// <summary> /// 建立Sql命令 /// </summary> /// <param name="type"></param> /// <returns></returns> public static IDbCommand CreateDbCommand(string sql, IDbConnection conn) { DateBaseType type = DateBaseType.NONE; if (conn is OracleConnection) { type = DateBaseType.ORACLE; } else if (conn is SqlConnection) { type = DateBaseType.SQLSERVER; } else if (conn is MySqlConnection) { type = DateBaseType.MYSQL; } else if (conn is OleDbConnection) { type = DateBaseType.ACCESS; } else if (conn is SQLiteConnection) { type = DateBaseType.SQLLITE; } IDbCommand cmd = null; switch (type) { case DateBaseType.ORACLE: cmd = new OracleCommand(sql, (OracleConnection)conn); break; case DateBaseType.SQLSERVER: cmd = new SqlCommand(sql, (SqlConnection)conn); break; case DateBaseType.MYSQL: cmd = new MySqlCommand(sql, (MySqlConnection)conn); break; case DateBaseType.ACCESS: cmd = new OleDbCommand(sql, (OleDbConnection)conn); break; case DateBaseType.SQLLITE: cmd = new SQLiteCommand(sql, (SQLiteConnection)conn); break; case DateBaseType.NONE: throw new Exception("未设置数据库类型"); default: throw new Exception("不支持该数据库类型"); } return(cmd); }
/// <summary> /// 建立Sql填充 /// </summary> /// <param name="type"></param> /// <returns></returns> public static IDbDataAdapter CreateDbAdapter(IDbCommand cmd) { DateBaseType type = DateBaseType.NONE; if (cmd is OracleCommand) { type = DateBaseType.ORACLE; } else if (cmd is SqlCommand) { type = DateBaseType.SQLSERVER; } else if (cmd is MySqlCommand) { type = DateBaseType.MYSQL; } else if (cmd is OleDbCommand) { type = DateBaseType.ACCESS; } else if (cmd is SQLiteCommand) { type = DateBaseType.SQLLITE; } IDbDataAdapter adapter = null; switch (type) { case DateBaseType.ORACLE: adapter = new OracleDataAdapter((OracleCommand)cmd); break; case DateBaseType.SQLSERVER: adapter = new SqlDataAdapter((SqlCommand)cmd); break; case DateBaseType.MYSQL: adapter = new MySqlDataAdapter((MySqlCommand)cmd); break; case DateBaseType.ACCESS: adapter = new OleDbDataAdapter((OleDbCommand)cmd); break; case DateBaseType.SQLLITE: adapter = new SQLiteDataAdapter((SQLiteCommand)cmd); break; case DateBaseType.NONE: throw new Exception("未设置数据库类型"); default: throw new Exception("不支持该数据库类型"); } return(adapter); }
/// <summary> /// 建立Sql参数 /// </summary> /// <param name="type"></param> /// <returns></returns> public static IDbDataParameter CreateDbSqlParameter(DateBaseType type) { Stopwatch sw = new Stopwatch(); sw.Start(); IDbDataParameter parameter = null; switch (type) { case DateBaseType.ORACLE: parameter = new OracleParameter(); break; case DateBaseType.SQLSERVER: parameter = new SqlParameter(); break; case DateBaseType.MYSQL: parameter = new MySqlParameter(); break; case DateBaseType.ACCESS: parameter = new OleDbParameter(); break; //case DateBaseType.SQLLITE: // parameter = new SQLiteParameter(); // break; case DateBaseType.NONE: throw new Exception("未设置数据库类型"); default: throw new Exception("不支持该数据库类型"); } sw.Stop(); var a = sw.ElapsedMilliseconds; return(parameter); }
public SqlOpertionHelper(string connectionString, DateBaseType data_type) { type = data_type; conn = DBFactory.CreateDbConnection(type, connectionString); }
/// <summary> /// 建立Sql命令 /// </summary> /// <param name="type"></param> /// <returns></returns> public static IDbTransaction CreateTransaction(IDbConnection conn) { DateBaseType type = DateBaseType.NONE; if (conn is OracleConnection) { type = DateBaseType.ORACLE; } else if (conn is SqlConnection) { type = DateBaseType.SQLSERVER; } else if (conn is MySqlConnection) { type = DateBaseType.MYSQL; } else if (conn is OleDbConnection) { type = DateBaseType.ACCESS; } else if (conn is SQLiteConnection) { type = DateBaseType.SQLLITE; } IDbTransaction tran = null; switch (type) { case DateBaseType.ORACLE: { OracleConnection connection = conn as OracleConnection; tran = connection.BeginTransaction(IsolationLevel.RepeatableRead); } break; case DateBaseType.SQLSERVER: { SqlConnection connection = conn as SqlConnection; tran = connection.BeginTransaction(IsolationLevel.RepeatableRead); } break; case DateBaseType.MYSQL: { MySqlConnection connection = conn as MySqlConnection; tran = connection.BeginTransaction(IsolationLevel.RepeatableRead); } break; case DateBaseType.ACCESS: { OleDbConnection connection = conn as OleDbConnection; tran = connection.BeginTransaction(IsolationLevel.RepeatableRead); } break; case DateBaseType.SQLLITE: { SQLiteConnection connection = conn as SQLiteConnection; tran = connection.BeginTransaction(IsolationLevel.RepeatableRead); } break; case DateBaseType.NONE: throw new Exception("未设置数据库类型"); default: throw new Exception("不支持该数据库类型"); } return(tran); }