public void ExecuteReader(DBSettingEntity dbSetting, Func <IDataReader, bool> funcProccessDataReader) { try { using (IDbConnection con = DBManagerFactory.BuilConnection(dbSetting.ProviderType, dbSetting.ConnectionString)) { con.Open(); IDbTransaction idbTransaction = null; if (dbSetting.IsTransaction) { idbTransaction = con.BeginTransaction(); } using (IDbCommand cmd = DBManagerFactory.BuildCommand(dbSetting.ProviderType, con, idbTransaction, dbSetting.CommandType, dbSetting.CommandText)) { this.AttachParameters(cmd, dbSetting.Parameters, dbSetting.ProviderType); using (IDataReader dr = cmd.ExecuteReader()) { funcProccessDataReader.Invoke(dr); } if (idbTransaction != null) { idbTransaction.Commit(); } } } } catch (SqlException ex) { throw this.TranslateException(ex); } }
private void AttachParameters(IDbCommand command, List <DBParameterEntity> lstParams, DataProvider providerType) { foreach (DBParameterEntity item in lstParams) { command.Parameters.Add(DBManagerFactory.BuildParameter(providerType, item.ParameterName, item.ParameterValue)); } }
public int ExecuteNonQuery(CommandType commandType, string commandText) { dbEntity.Command = DBManagerFactory.GetCommand(dbEntity.ProviderType); this.PrepareCommand(dbEntity.Command, dbEntity.Connection, dbEntity.Transaction, commandType, commandText, dbEntity.Parameters); int returnValue = dbEntity.Command.ExecuteNonQuery(); dbEntity.Command.Parameters.Clear(); return(returnValue); }
public void CreateAndOpenConnection() { dbEntity.Connection = DBManagerFactory.GetConnection(dbEntity.ProviderType); dbEntity.Connection.ConnectionString = dbEntity.ConnectionString; if (dbEntity.Connection.State != ConnectionState.Open) { dbEntity.Connection.Open(); } }
public IDataReader ExecuteReader(CommandType commandType, string commandText) { dbEntity.Command = DBManagerFactory.GetCommand(dbEntity.ProviderType); dbEntity.Command.Connection = dbEntity.Connection; PrepareCommand(dbEntity.Command, dbEntity.Connection, dbEntity.Transaction, commandType, commandText, dbEntity.Parameters); dbEntity.DataReader = dbEntity.Command.ExecuteReader(); dbEntity.Command.Parameters.Clear(); return(dbEntity.DataReader); }
public DataSet ExecuteDataSet(CommandType commandType, string commandText) { dbEntity.Command = DBManagerFactory.GetCommand(dbEntity.ProviderType); this.PrepareCommand(dbEntity.Command, dbEntity.Connection, dbEntity.Transaction, commandType, commandText, dbEntity.Parameters); IDbDataAdapter dataAdapter = DBManagerFactory.GetDataAdapter(dbEntity.ProviderType); dataAdapter.SelectCommand = dbEntity.Command; DataSet dataSet = new DataSet(); dataAdapter.Fill(dataSet); dbEntity.Command.Parameters.Clear(); return(dataSet); }
public object ExecuteScalar(DBSettingEntity dbSetting) { try { object result; using (IDbConnection con = DBManagerFactory.BuilConnection(dbSetting.ProviderType, dbSetting.ConnectionString)) { con.Open(); IDbTransaction idbTransaction = null; if (dbSetting.IsTransaction) { idbTransaction = con.BeginTransaction(); } using (IDbCommand cmd = DBManagerFactory.BuildCommand(dbSetting.ProviderType, con, idbTransaction, dbSetting.CommandType, dbSetting.CommandText)) { this.AttachParameters(cmd, dbSetting.Parameters, dbSetting.ProviderType); result = cmd.ExecuteScalar(); if (idbTransaction != null) { idbTransaction.Commit(); } } } return(result); } catch (SqlException ex) { throw this.TranslateException(ex); } }
public void ExecuteDataSet(DBSettingEntity dbSetting, Func <DataSet, bool> funcProccessDataSet) { try { using (IDbConnection con = DBManagerFactory.BuilConnection(dbSetting.ProviderType, dbSetting.ConnectionString)) { con.Open(); IDbTransaction idbTransaction = null; if (dbSetting.IsTransaction) { idbTransaction = con.BeginTransaction(); } using (IDbCommand cmd = DBManagerFactory.BuildCommand(dbSetting.ProviderType, con, idbTransaction, dbSetting.CommandType, dbSetting.CommandText)) { this.AttachParameters(cmd, dbSetting.Parameters, dbSetting.ProviderType); IDbDataAdapter dataAdapter = DBManagerFactory.GetDataAdapter(dbSetting.ProviderType); dataAdapter.SelectCommand = cmd; DataSet dataSet = new DataSet(); dataAdapter.Fill(dataSet); funcProccessDataSet.Invoke(dataSet); if (idbTransaction != null) { idbTransaction.Commit(); } } } } catch (SqlException ex) { throw this.TranslateException(ex); } }
public void CreateParameters(int paramsCount) { dbEntity.Parameters = new IDbDataParameter[paramsCount]; dbEntity.Parameters = DBManagerFactory.GetParameters(dbEntity.ProviderType, paramsCount); }