/// <summary> /// method to execute the dataset property of the command object /// </summary> /// <param name="commandType"></param> /// <param name="commandText"></param> /// <returns></returns> public DataTable GetData(CommandType commandType, string commandText) { DataTable dt = null; try { // get the command object from the DBManagerFactory this.idbCommand = DBManagerFactory.GetCommand(this.ProviderType); // method to prepare the oommand object PrepareCommand(idbCommand, this.Connection, this.Transaction, commandType, commandText, this.Parameters); // get the data adapter from DBManagerFactory IDbDataAdapter dataAdapter = DBManagerFactory.GetDataAdapter(this.ProviderType); // assign the selected command property dataAdapter.SelectCommand = idbCommand; DataSet dataSet = new DataSet(); // fill the dataset dataAdapter.Fill(dataSet); // clear the command parameters idbCommand.Parameters.Clear(); dt = dataSet.Tables[0]; dataSet.Dispose(); return(dt); } catch (Exception ex) { throw ex; } }
/// <summary> /// mehod to open the connection to the data base /// </summary> public void Open() { try { // calling method from DBManagerFactory class to get the provider type connection object idbConnection = DBManagerFactory.GetConnection(this.providerType); // passing connection string idbConnection.ConnectionString = this.ConnectionString; if (idbConnection.State == ConnectionState.Open) { idbConnection.Close(); } // chek for open connection state if (idbConnection.State != ConnectionState.Open) { idbConnection.Open(); } // calling method from DBManagerFactory class to get the provider type command object this.idbCommand = DBManagerFactory.GetCommand(this.ProviderType); this.idbTransaction = DBManagerFactory.GetTransaction(idbConnection, this.ProviderType); } catch (Exception ex) { throw ex; } }
/// <summary> /// method to execute thte scalar property of the command object /// </summary> /// <param name="commandType"></param> /// <param name="commandText"></param> /// <returns></returns> public object ExecuteScalar(CommandType commandType, string commandText) { try { // get the command object for DBManagerFactory this.idbCommand = DBManagerFactory.GetCommand(this.ProviderType); // prepare the command object PrepareCommand(idbCommand, this.Connection, this.Transaction, commandType, commandText, this.Parameters); // get the scalar return value to object object returnValue = idbCommand.ExecuteScalar(); // clear the paerameters idbCommand.Parameters.Clear(); return(returnValue); } catch (Exception ex) { throw ex; } }
/// <summary> /// method to execute the non query /// </summary> /// <param name="commandType"></param> /// <param name="commandText"></param> /// <returns></returns> public int ExecuteNonQuery(CommandType commandType, string commandText) { try { // get the command object from DBManagerFactory this.idbCommand = DBManagerFactory.GetCommand(this.ProviderType); // prepare the command object PrepareCommand(idbCommand, this.Connection, this.Transaction, commandType, commandText, this.Parameters); // get the executed value int returnValue = idbCommand.ExecuteNonQuery(); // clear the command parameters idbCommand.Parameters.Clear(); return(returnValue); } catch (Exception ex) { throw ex; } }
/// <summary> /// method to execute the reader of the specific provider /// </summary> /// <param name="commandType"></param> /// <param name="commandText"></param> /// <returns></returns> public IDataReader ExecuteReader(CommandType commandType, string commandText) { try { // get the command object from DBManagerFactory by the provider type this.idbCommand = DBManagerFactory.GetCommand(this.ProviderType); // assingn the connection property to thcommand object idbCommand.Connection = this.Connection; // prepare the command object with the parameters PrepareCommand(idbCommand, this.Connection, this.Transaction, commandType, commandText, this.Parameters); // assign the datareader this.DataReader = idbCommand.ExecuteReader(); // clear the paramerts idbCommand.Parameters.Clear(); return(this.DataReader); } catch (Exception ex) { throw ex; } }