using System; using System.Reflection; using System.Data; using System.Data.OleDb; using System.Data.SqlClient; namespace CSharpCorner.ProviderFactory {///
} # Endregion # region Provider propertypublic ProviderType Provider {get {return _provider;} set {_provider = value;}} # endregion # region IDbConnection methodspublic IDbConnection CreateConnection () {IDbConnection conn = null; try {conn = (IDbConnection) Activator.CreateInstance (_connectionTypes [(int) _provider]);} catch (TargetInvocationException e) {throw new SystemException (e.InnerException.Message, e.InnerException);} return conn;} public IDbConnection CreateConnection (string connectionString) {IDbConnection conn = null; object [] args = {connectionString}; try {conn = (IDbConnection) Activator.CreateInstance (_connectionTypes [(int) _provider], args);} catch (TargetInvocationException e) {throw new SystemException (e.InnerException.Message, e. InnerException);} return conn;} # endregion # region IDbCommand methodspublic IDbCommand CreateCommand () {IDbCommand cmd = null; try {cmd = (IDbCommand) Activator.CreateInstance (_commandTypes [(int) _provider]);} catch (TargetInvocationException e) {throw new systemException (EI nnerException.Message, e.InnerException);} return cmd;} public IDbCommand CreateCommand (string cmdText) {IDbCommand cmd = null; object [] args = {cmdText}; try {cmd = (IDbCommand) Activator.CreateInstance (_commandTypes [( int) _provider], args);} catch (TargetInvocationException e) {throw new SystemException (e.InnerException.Message, e.InnerException);} return cmd;} public IDbCommand CreateCommand (string cmdText, IDbConnection connection) {IDbCommand cmd = null ; object [] args = {cmdText, connection}; try {cmd = (IDbCommand) Activator.CreateInstance (_commandTypes [(int) _provider], args);} catch (TargetInvocationException e) {throw new SystemException (e.InnerException.Message , e.innerexception;} Return CMD;
} Public IDbCommand CreateCommand (string cmdText, IDbConnection connection, IDbTransaction transaction) {IDbCommand cmd = null; object [] args = {cmdText, connection, transaction}; try {cmd = (IDbCommand) Activator.CreateInstance (_commandTypes [(int) _provider ], args);} catch (TargetInvocationException e) {throw new SystemException (e.InnerException.Message, e.InnerException);} return cmd;} # endregion # region IDbDataAdapter methodspublic IDbDataAdapter CreateDataAdapter () {IDbDataAdapter da = null; try { da = (IDbDataAdapter) Activator.CreateInstance (_dataAdapterTypes [(int) _provider]);} catch (TargetInvocationException e) {throw new SystemException (e.InnerException.Message, e.InnerException);} return da;} public IDbDataAdapter CreateDataAdapter (IDbCommand selectCommand) {IDbDataAdapter da = null; object [] args = {selectCommand}; try {da = (IDbDataAdapter) Activator.CreateInstance (_dataAdapterTypes [(int) _provider], args);} catch (TargetInvocationException e) {throw new SystemException ( E.Nnerexception.Message, e.InnerException);} return da;} public IDbDataAdapter CreateDataAdapter (string selectCommandText, IDbConnection selectConnection) {IDbDataAdapter da = null; object [] args = {selectCommandText, selectConnection}; try {da = (IDbDataAdapter) Activator.CreateInstance (_dataAdapterTypes [ (int) _provider], args);} catch (TargetInvocationException e) {throw new SystemException (e.InnerException.Message, e.InnerException);} return da;} public IDbDataAdapter CreateDataAdapter (string selectCommandText, string selectConnectionString) {IDbDataAdapter da = Null; object [] args = {selectcommandtext, selectconnectionstring}; try {da = (idbdataadapter) activator.createInstance (_Dataadaptertypes [(int) _provider], args;