C#多数据库组件包,支持MSSQL+Oracle+MySQL+用户操作手册|C/S开发框架
C#多数据库组件包支持MSSQL+Oracle+MySQL+用户操作手册|C/S框架网
![C#多数据库组件包支持MSSQL+Oracle+MySQL+用户操作手册|C/S框架网](http://www.csframework.com/upload/image/%E5%BE%AE%E4%BF%A1%E6%88%AA%E5%9B%BE_20181217004101.png)
我们在开发软件过程中,特别是基于数据管理应用相关的系统,一般采用一种数据库,如Microsoft SQL Server,超大型系统有的使用Oracle,部分Web系统采用开源的MySQL等,由于各种业务场景以及用户需求,促使我们的数据库系统部署在不同类型的数据库服务器上。若开发的系统能支持多种数据库的快速切换,可以为我们减少很多烦恼,同时提高系统的适应性、兼容性以及可扩展性。
C/S框架网为广大用户定制开发一套基于C#语言的多数据库组件包,以及用户操作手册。
C#语言多数据库组件包(支持MSSQL+Oracle+MySQL)
CSFramework.DB.realease.rar
下载链接:https://pan.baidu.com/s/1bmzNVwQ4-F2svTLByIPaQA 密码:fy9s
![贴图图片](http://www.csframework.com/upload/image/7373b87554ac46da9f1b8ed24928d097.png)
《CSFramework.DB用户操作手册》.pdf
下载链接:https://pan.baidu.com/s/1rauYthmGjHQ5T8IeLuG0Ww 密码:1fsu
![基于C#语言多数据库组件包及用户操作手册](http://www.csframework.com/upload/image/68b430ff34b1439d88560a9644726610.png)
C# Code:
/// <summary>
/// IDatabase数据库接口
/// </summary>
public interface IDatabase : IAdoFactory
{
int DefaultPort { get; }
int CommandTimeout { get; }
int ConnectionTimeout { get; }
Type DateTimeType { get; }
DateTime GetServerTime();
String ConnectionString { get; set; }
DbTransaction TransBegin();
void TransCommit(DbTransaction trans, bool closeConnection = false);
void TransRollback(DbTransaction trans, bool closeConnection = false);
DataSet GetDataSet(string SQL);
DataSet GetDataSet(DbCommand cmd);
DataSet GetDataSet(string text, CommandType type, IDataParameter[] paras);
DataTable GetTable(string SQL, string tableName = "");
DataTable GetTable(DbCommand cmd, string tableName = "");
DataRow GetDataRow(string SQL);
int ExecuteSQL(string SQL);
int ExecuteCommand(DbCommand cmd);
object ExecuteScalar(string SQL);
object ExecuteScalar(DbCommand cmd);
DbDataReader ExecuteReader(string SQL);
DbDataReader ExecuteReader(DbCommand cmd);
List<T> ExecuteReader<T>(string SQL, Func<DbDataReader, T> action) where T : new();
List<T> ExecuteReader<T>(DbCommand cmd, Func<DbDataReader, T> action) where T : new();
T ExecuteReader<T>(DbCommand cmd) where T : new();
T ExecuteReader<T>(string SQL) where T : new();
int ExecuteTrans(DbTransaction trans, string SQL);
void Close(DbConnection connection);
}
//来源:C/S框架网(www.csframework.com) QQ:23404761
/// <summary>
/// IDatabase数据库接口
/// </summary>
public interface IDatabase : IAdoFactory
{
int DefaultPort { get; }
int CommandTimeout { get; }
int ConnectionTimeout { get; }
Type DateTimeType { get; }
DateTime GetServerTime();
String ConnectionString { get; set; }
DbTransaction TransBegin();
void TransCommit(DbTransaction trans, bool closeConnection = false);
void TransRollback(DbTransaction trans, bool closeConnection = false);
DataSet GetDataSet(string SQL);
DataSet GetDataSet(DbCommand cmd);
DataSet GetDataSet(string text, CommandType type, IDataParameter[] paras);
DataTable GetTable(string SQL, string tableName = "");
DataTable GetTable(DbCommand cmd, string tableName = "");
DataRow GetDataRow(string SQL);
int ExecuteSQL(string SQL);
int ExecuteCommand(DbCommand cmd);
object ExecuteScalar(string SQL);
object ExecuteScalar(DbCommand cmd);
DbDataReader ExecuteReader(string SQL);
DbDataReader ExecuteReader(DbCommand cmd);
List<T> ExecuteReader<T>(string SQL, Func<DbDataReader, T> action) where T : new();
List<T> ExecuteReader<T>(DbCommand cmd, Func<DbDataReader, T> action) where T : new();
T ExecuteReader<T>(DbCommand cmd) where T : new();
T ExecuteReader<T>(string SQL) where T : new();
int ExecuteTrans(DbTransaction trans, string SQL);
void Close(DbConnection connection);
}
//来源:C/S框架网(www.csframework.com) QQ:23404761
C# Code:
/// <summary>
/// ADO(ActiveX Data Object)ADO.NET活动数据对象工厂
/// </summary>
public interface IAdoFactory
{
string BuildConnectionString(string server, int port, string dbName, string uid, string pwd, int timeout = 10);
CommandHelper CreateSqlProc(string spName);
CommandHelper CreateCommand(string commandText);
/// <summary>
/// DbCommand的参数符号,@,?
/// </summary>
string ParamSymboName { get; }
DbParameter CreateTimestampParameter(string parameterName, string fieldName);
DbConnection CreateConnection();
DbConnection CreateConnection(string connectionString);
DbCommand CreateCommand(string commandText, CommandType commandType);
DbParameter CreateParameter(string parameterName, object parameterValue);
DbCommandBuilder CreateCommandBuilder();
DbDataAdapter CreateDataAdapter();
DbDataAdapter CreateDataAdapter(AdapterRowUpdatingEvent eventHandler);
}
//来源:C/S框架网(www.csframework.com) QQ:23404761
/// <summary>
/// ADO(ActiveX Data Object)ADO.NET活动数据对象工厂
/// </summary>
public interface IAdoFactory
{
string BuildConnectionString(string server, int port, string dbName, string uid, string pwd, int timeout = 10);
CommandHelper CreateSqlProc(string spName);
CommandHelper CreateCommand(string commandText);
/// <summary>
/// DbCommand的参数符号,@,?
/// </summary>
string ParamSymboName { get; }
DbParameter CreateTimestampParameter(string parameterName, string fieldName);
DbConnection CreateConnection();
DbConnection CreateConnection(string connectionString);
DbCommand CreateCommand(string commandText, CommandType commandType);
DbParameter CreateParameter(string parameterName, object parameterValue);
DbCommandBuilder CreateCommandBuilder();
DbDataAdapter CreateDataAdapter();
DbDataAdapter CreateDataAdapter(AdapterRowUpdatingEvent eventHandler);
}
//来源:C/S框架网(www.csframework.com) QQ:23404761
C# Code:
/// <summary>
/// 数据库对象工厂
/// </summary>
public static class DatabaseFactory
{
/// <summary>
/// 创建数据库(使用DataProviderFactory创建数据存取基础组件,通用版)
/// </summary>
/// <param name="providerType">数据库类型</param>
/// <param name="connectionString">数据库连接字符串</param>
/// <returns></returns>
public static IDatabase CreateMDB(DatabaseType providerType, string connectionString)
{
return new DatabaseMDB(providerType, connectionString);
}
/// <summary>
/// 创建SQL Server数据库
/// </summary>
/// <param name="connectionString">数据库连接字符串</param>
/// <returns></returns>
public static IDatabase CreateSqlDatabase(string connectionString)
{
return new DatabaseMSSQL(connectionString);
}
/// <summary>
/// 创建MySQL数据库
/// </summary>
/// <param name="connectionString">数据库连接字符串</param>
/// <returns></returns>
public static IDatabase CreateMySqlDatabase(string connectionString)
{
return new DatabaseMySQL(connectionString);
}
/// <summary>
/// 创建Oracle数据库
/// </summary>
/// <param name="connectionString">数据库连接字符串</param>
/// <returns></returns>
public static IDatabase CreateOracleDatabase(string connectionString)
{
return new DatabaseOracle(connectionString);
}
/// <summary>
/// 创建数据库
/// </summary>
/// <param name="dbType">数据库类型</param>
/// <param name="connectionString">数据库连接字符串</param>
/// <returns></returns>
public static IDatabase CreateDatabase(DatabaseType dbType, string connectionString)
{
if (dbType == DatabaseType.SqlServer)
return new DatabaseMSSQL(connectionString);
if (dbType == DatabaseType.MySQL)
return new DatabaseMySQL(connectionString);
if (dbType == DatabaseType.Oracle)
return new DatabaseOracle(connectionString);
throw new Exception("未支持的数据库类型!");
}
/// <summary>
/// 创建数据库
/// </summary>
/// <param name="dbType">数据库类型</param>
/// <param name="connectionString">数据库连接字符串</param>
/// <returns></returns>
public static IDatabase CreateDatabase(string dbType, string connectionString)
{
DatabaseType databaseType;
if (!Enum.TryParse<DatabaseType>(dbType, true, out databaseType))
throw new Exception("不支持的数据库类型!");
if (databaseType == DatabaseType.SqlServer)
return new DatabaseMSSQL(connectionString);
if (databaseType == DatabaseType.MySQL)
return new DatabaseMySQL(connectionString);
if (databaseType == DatabaseType.Oracle)
return new DatabaseOracle(connectionString);
throw new Exception("未支持的数据库类型!");
}
/// <summary>
/// ADO组件工厂
/// </summary>
/// <param name="dbType">数据库类型</param>
/// <param name="connectionString">数据连接字符串</param>
/// <returns></returns>
public static IAdoFactory GetADOFactory(DatabaseType dbType, string connectionString)
{
return CreateDatabase(dbType, connectionString);
}
}
//来源:C/S框架网(www.csframework.com) QQ:23404761
/// <summary>
/// 数据库对象工厂
/// </summary>
public static class DatabaseFactory
{
/// <summary>
/// 创建数据库(使用DataProviderFactory创建数据存取基础组件,通用版)
/// </summary>
/// <param name="providerType">数据库类型</param>
/// <param name="connectionString">数据库连接字符串</param>
/// <returns></returns>
public static IDatabase CreateMDB(DatabaseType providerType, string connectionString)
{
return new DatabaseMDB(providerType, connectionString);
}
/// <summary>
/// 创建SQL Server数据库
/// </summary>
/// <param name="connectionString">数据库连接字符串</param>
/// <returns></returns>
public static IDatabase CreateSqlDatabase(string connectionString)
{
return new DatabaseMSSQL(connectionString);
}
/// <summary>
/// 创建MySQL数据库
/// </summary>
/// <param name="connectionString">数据库连接字符串</param>
/// <returns></returns>
public static IDatabase CreateMySqlDatabase(string connectionString)
{
return new DatabaseMySQL(connectionString);
}
/// <summary>
/// 创建Oracle数据库
/// </summary>
/// <param name="connectionString">数据库连接字符串</param>
/// <returns></returns>
public static IDatabase CreateOracleDatabase(string connectionString)
{
return new DatabaseOracle(connectionString);
}
/// <summary>
/// 创建数据库
/// </summary>
/// <param name="dbType">数据库类型</param>
/// <param name="connectionString">数据库连接字符串</param>
/// <returns></returns>
public static IDatabase CreateDatabase(DatabaseType dbType, string connectionString)
{
if (dbType == DatabaseType.SqlServer)
return new DatabaseMSSQL(connectionString);
if (dbType == DatabaseType.MySQL)
return new DatabaseMySQL(connectionString);
if (dbType == DatabaseType.Oracle)
return new DatabaseOracle(connectionString);
throw new Exception("未支持的数据库类型!");
}
/// <summary>
/// 创建数据库
/// </summary>
/// <param name="dbType">数据库类型</param>
/// <param name="connectionString">数据库连接字符串</param>
/// <returns></returns>
public static IDatabase CreateDatabase(string dbType, string connectionString)
{
DatabaseType databaseType;
if (!Enum.TryParse<DatabaseType>(dbType, true, out databaseType))
throw new Exception("不支持的数据库类型!");
if (databaseType == DatabaseType.SqlServer)
return new DatabaseMSSQL(connectionString);
if (databaseType == DatabaseType.MySQL)
return new DatabaseMySQL(connectionString);
if (databaseType == DatabaseType.Oracle)
return new DatabaseOracle(connectionString);
throw new Exception("未支持的数据库类型!");
}
/// <summary>
/// ADO组件工厂
/// </summary>
/// <param name="dbType">数据库类型</param>
/// <param name="connectionString">数据连接字符串</param>
/// <returns></returns>
public static IAdoFactory GetADOFactory(DatabaseType dbType, string connectionString)
{
return CreateDatabase(dbType, connectionString);
}
}
//来源:C/S框架网(www.csframework.com) QQ:23404761
相关文章:
如何使用多数据库IDatabase接口以及数据访问层应用
![](http://www.csframework.com/images/our03.gif)