/// <summary> /// This method uses the Microsoft.ApplicationBlocks.Data /// Method to fill a DataSet. /// </summary> /// <param name="storedProcedure">The 'StoredProcedure' to execute.</param> /// <returns>A DataSet if successful or null if not. Always test for null /// befure using the returned data set.</returns> public DataSet LoadDataSet(StoredProcedure storedProcedure, DataConnector databaseConnector) { // initial value DataSet dataSet = null; // Execute StoredProcedure dataSet = SqlHelper.ExecuteDataset(databaseConnector.SqlConnector, CommandType.StoredProcedure, storedProcedure.ProcedureName, storedProcedure.Parameters); // return value return(dataSet); }
/// <summary> /// This method uses the Microsoft.ApplicationBlocks.Data /// Method to insert a new record. /// </summary> /// <param name="storedProcedure">The 'StoredProcedure' to execute.</param> /// <returns>The identity value of the new record if successful or /// -1 if not. /// </returns> public int InsertRecord(StoredProcedure storedProcedure, DataConnector databaseConnector) { // initial value int identity = -1; // Execute StoredProcedure identity = Convert.ToInt32(SqlHelper.ExecuteScalar(databaseConnector.SqlConnector, CommandType.StoredProcedure, storedProcedure.ProcedureName, storedProcedure.Parameters)); // return value return(identity); }
/// <summary> /// This method uses the Microsoft.ApplicationBlocks.Data /// Method to update an existing record by executing /// a query that does not return anything. (ExecuteNonQuery). /// </summary> /// <param name="storedProcedure">The 'StoredProcedure' to execute.</param> /// <returns>True as long as there is not an error, false if there is. /// </returns> public bool UpdateRecord(StoredProcedure storedProcedure, DataConnector databaseConnector) { // initial value bool saved = false; // Execute StoredProcedure SqlHelper.ExecuteNonQuery(databaseConnector.SqlConnector, CommandType.StoredProcedure, storedProcedure.ProcedureName, storedProcedure.Parameters); // set saved to true saved = true; // return value return(saved); }
/// <summary> /// This method (safely) returns the Data Connector from the /// AppController.DataBridget.DataManager.DataConnector /// </summary> public DataConnector GetDataConnector() { // initial value DataConnector dataConnector = null; // if the DataBridge exists if (this.HasDataBridge) { // return the DataConnector from the DataBridge dataConnector = this.DataBridge.GetDataConnector(); } // return value return(dataConnector); }
/// <summary> /// This method (safely) returns the Data Connector from the /// AppController.DataBridget.DataManager.DataConnector /// </summary> public DataConnector GetDataConnector() { // initial value DataConnector dataConnector = null; // if the DataManager exists if (this.HasDataManager) { // return the DataConnector from the DataManager dataConnector = this.DataManager.DataConnector; } // return value return(dataConnector); }
/// <summary> /// This method (safely) returns the Data Connector from the /// AppController.DataBridget.DataManager.DataConnector /// </summary> private DataConnector GetDataConnector() { // initial value DataConnector dataConnector = null; // if the AppController exists if (this.AppController != null) { // return the DataConnector from the AppController dataConnector = this.AppController.GetDataConnector(); } // return value return(dataConnector); }
/// <summary> /// This method is used to execute a query that does not return a value. /// To call this method, you must set following: /// </summary> /// <param name="parameters">The parameters must be set to call this method. /// 1. 'ProcedureName' - The String value must be set for this parameter. /// 2. 'SqlParameters' (Optional) - If the stored procedure to be called requires parameters /// then you must pass in the SqlParameters[] array as this parameter. /// It does not matter the order of these parameters. /// </param> /// <param name="dataConnector">The database connection to use to execute this procedure.</param> /// A successful will call will set returnValue.Boolean to true (executed) /// In the event the procedure does not execute (returnValue.Boolean = false) /// check the following: /// returnValue.Name = 'Error" - Will be set to error /// returnValue.Text = Will be set to the Exception.ToString(); /// returnValue.Object = Will Contain the Exception that occurred. public PolymorphicObject ExecuteNonQuery(List <PolymorphicObject> parameters, DataConnector dataConnector) { // initial value PolymorphicObject returnValue = new PolymorphicObject(); // Set to false returnValue.Boolean = new NullableBoolean(false); // locals bool executed = false; try { // If the data connection is connected if ((dataConnector != null) && (dataConnector.Connected == true)) { // Create a StoredProcedure StoredProcedure storedProcedure = new StoredProcedure(); // Create a StoredProcedure object storedProcedure.ProcedureName = FindProcedureName(parameters); // Set the Parameters for the StoredProcedure storedProcedure.Parameters = FindSqlParameters(parameters); // if the ProcedureName is set if (!String.IsNullOrEmpty(storedProcedure.ProcedureName)) { // Create an instance of the DataHelper DataHelper dataHelper = new DataHelper(); // Perform an update executed = dataHelper.UpdateRecord(storedProcedure, dataConnector); // set the return value returnValue.Boolean = new NullableBoolean(executed); } } else { // Raise Error Data Connection Not Available throw new Exception("The database connection is not available."); } } catch (Exception error) { // for debugging only string err = error.ToString(); // Set the text of the returnValue.Name = "Error"; // Set the text for the returnValue returnValue.Text = err; // set the return value returnValue.ObjectValue = error; } // return value return(returnValue); }
/// <summary> /// Tests the connection to the database /// </summary> internal PolymorphicObject TestDataConnection(List <PolymorphicObject> parameters, DataConnector dataConnector) { // Initial Value PolymorphicObject returnObject = new PolymorphicObject(); // Create returnObject.Boolean returnObject.Boolean = new NullableBoolean(); // If the data connection is connected if ((dataConnector != null) && (dataConnector.Connected == true)) { // Set Boolean To True returnObject.Boolean.Value = NullableBooleanEnum.True; } else { // Raise Error Data Connection Not Available throw new Exception("The database connection is not available."); } // return value return(returnObject); }