纽威
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

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
{
/// <summary>
/// 根据配置文件中所配置的数据库类型
/// 来获取命令参数中的参数符号oracle为":",sqlserver为"@"
/// </summary>
/// <returns></returns>
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;
}
/// <summary>
/// 根据配置文件中所配置的数据库类型
/// 来创建相应数据库命令对象
/// </summary>
/// <returns></returns>
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;
}
}
}