///-------------------------------------------------------------------------------- /// <summary>This method sets up a stored procedure command, loaded with values from /// the input data access object where appropriate.</summary> /// /// <param name="sprocName">Name of the stored procedure.</param> /// <param name="sprocParams">The input stored procedure parameter values.</param> /// /// <returns>A DbCommand for the stored procedure.</returns> ///-------------------------------------------------------------------------------- public DbCommand SetupSprocCommand(string sprocName, NameObjectCollection sprocParams) { GenericMethod sprocMethod = null; DbCommand command = null; try { // get sproc method from cache or db sprocMethod = DbProcs.MethodList.Find("MethodName", sprocName); if (sprocMethod == null) { // get sproc from db an add to cache sprocMethod = GetSprocFromDB(sprocName, true); } // set up the base command information command = _database.GetStoredProcCommand(sprocName); command.Connection = Connection; command.CommandTimeout = DBOptions.CommandTimeout; // load the sproc parameters with input data if found foreach (GenericParameter loopParameter in sprocMethod.MethodParameterList) { bool foundValue = false; if (sprocParams[loopParameter.ParameterName] != null && sprocParams[loopParameter.ParameterName].GetString() != String.Empty) { foundValue = true; } if (foundValue == false && loopParameter.IsNullable == false && loopParameter.ParameterTypeCode == 1) { // required parameter not found, throw exception throw new System.Exception("MoPlus.Data.BuildSprocParamsWithInputValues - required input value parameter " + loopParameter.ParameterName + " for stored procedure " + sprocName + " not found."); } _database.AddParameter(command, loopParameter.ParameterName, SqlHelper.GetDbTypeFromSqlDataType(loopParameter.DataTypeCode), loopParameter.Size, SqlHelper.GetParameterDirectionFromColumnType(loopParameter.ParameterTypeCode), loopParameter.IsNullable, (byte)loopParameter.Precision, (byte)4, loopParameter.ParameterName, DataRowVersion.Default, sprocParams[loopParameter.ParameterName]); } } catch (Exception ex) { bool reThrow = ExceptionHandler.HandleException(ex); if (reThrow) { throw; } } return(command); }