예제 #1
0
        }//END StoreProcUpdate method

        // =====================================================================================
        /// <summary>
        /// public QueryUpdate method
        ///
        /// Execute a SqlCommand (that returns no resultset) against the database specified in the connection string
        /// using a stored procedure and the provided parameters.
        /// </summary>
        /// <remarks>
        /// e.g.:
        ///  int result = StoreProcUpdate("PublishOrders", new SqlParameter("@prodid", 24));
        /// </remarks>
        /// <param name="UpdateCommand">the name of the stored procedure to be used.)</param>
        /// <param name="CommandParameters">an array of SqlParamters used to execute the groupCommand</param>
        /// <returns>an int representing the number of rows affected by the groupCommand</returns>
        // -------------------------------------------------------------------------------------
        public static int QueryUpdate(string UpdateCommand, params SqlParameter [] CommandParameters)
        {
            //
            // Initialise method variables and objects.
            //
            int iResult = 0;

            using (SqlConnection conn = new SqlConnection(_connectionString))
            {
                conn.Open( );
                using (SqlTransaction trans = conn.BeginTransaction( ))
                {
                    try
                    {
                        iResult = EvSqlMethods.ExecuteNonQuery(
                            trans, CommandType.Text, UpdateCommand, CommandParameters);
                        trans.Commit( );
                    }
                    catch (Exception Ex)
                    {
                        trans.Rollback( );

                        string eventMessage = "Status: + " + EvSqlMethods.Status
                                              + "\r\n Connection String" + _connectionString
                                              + "\r\n Query: \r\n" + UpdateCommand
                                              + "\r\n Exception: \r\n" + Evado.Model.EvStatics.getException(Ex);

                        Evado.Model.EvStatics.WriteToEventLog(_eventLogSource, eventMessage, EventLogEntryType.Error);
                        throw (Ex);
                    }
                }
                return(iResult);
            }
        }//END QueryUpdate method
예제 #2
0
        }//END getBoolean static method

        //++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
        #endregion

        #region Reader column count methods

        /*
         * // =====================================================================================
         * /// <summary>
         * /// public getGuid static method
         * ///
         * /// Description:
         * /// Reads the row object and returns the newField name as a Gu
         * /// </summary>
         * /// <param name="Row">OdbcDataReader</param>
         * /// <param name="_id.
         * /// Document">Document</param>
         * // -------------------------------------------------------------------------------------
         * public static DocumentGuid getGuid ( SqlDataReader Reader, int Column )
         * {
         * if ( Reader [ Column ] != null )
         * {
         *  string sValue = Reader [ Column ].ToString( ).Trim( );
         *  if ( sValue.Length == 36 )
         *  {
         *    return new DocumentGuid( sValue );
         *  }
         * }
         *
         * return DocumentGuid.Empty;
         *
         * }//END getGuid static method
         *
         * // =====================================================================================
         * /// <summary>
         * /// public getInteger static method
         * ///
         * /// Description:
         * /// Reads the row object and returns the newField name as a Integer.
         * ///
         * /// </summary>
         * /// <param name="Row">OdbcDataReader</param>
         * /// <param name="document">Document</param>
         * // -------------------------------------------------------------------------------------
         * public static int getInteger ( SqlDataReader Reader, int Column )
         * {
         * int iValue = 0;
         *
         * if ( Reader [ Column ] != null )
         * {
         *  if ( int.TryParse( Reader [ Column ].ToString( ), out iValue ) == false )
         *  {
         *    return 0;
         *  }
         * }
         *
         * return iValue;
         *
         * }//END getInteger static method
         *
         * // =====================================================================================
         * /// <summary>
         * /// public getDateTime static method
         * ///
         * /// Description:
         * /// Reads the row object and returns the newField name as a DateTime object.
         * ///
         * /// </summary>
         * /// <param name="Row">OdbcDataReader</param>
         * /// <param name="document">Document</param>
         * // -------------------------------------------------------------------------------------
         * public static DateTime getDateTime ( SqlDataReader Reader, int Column )
         * {
         * DateTime dValue = DateTime.Parse( "1 Jan 1900" );
         *
         * if ( Reader [ Column ] != null )
         * {
         *  if ( DateTime.TryParse( Reader [ Column ].ToString( ), out dValue ) == false )
         *  {
         *    return DateTime.Parse( "1 Jan 1900" );
         *  }
         * }
         *
         * return dValue;
         *
         * }//END getDateTime static method
         *
         * // =====================================================================================
         * /// <summary>
         * /// public getString static method
         * ///
         * /// Description:
         * /// Reads the row object and returns the newField name as a string.
         * ///
         * /// </summary>
         * /// <param name="Row">OdbcDataReader</param>
         * /// <param name="document">Document</param>
         * // -------------------------------------------------------------------------------------
         * public static string getString ( SqlDataReader Reader, int Column )
         * {
         * if ( Reader [ Column ] != null )
         * {
         *  return Reader [ Column ].ToString( ).Trim( );
         * }
         * return String.Empty;
         *
         * }//END getString static method
         *
         * // =====================================================================================
         * /// <summary>
         * /// public getFloat static method
         * ///
         * /// Description:
         * /// Reads the row object and returns the newField name as a FormUid.
         * ///
         * /// </summary>
         * /// <param name="Row">OdbcDataReader</param>
         * /// <param name="document">Document</param>
         * // -------------------------------------------------------------------------------------
         * public static float getFloat ( SqlDataReader Reader, int Column )
         * {
         * float fValue = 0 ;
         *
         * if ( Reader [ Column ] != null )
         * {
         *  if ( float.TryParse( Reader [ Column ].ToString( ), out fValue ) == false )
         *  {
         *    return 0 ;
         *  }
         * }
         *
         * return fValue;
         *
         * }//END getFloat static method
         */
        //++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
        #endregion

        //++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
        #endregion

        #region Update Methods

        // =====================================================================================
        /// <summary>
        /// public StoreProcUpdate method
        ///
        /// Execute a SqlCommand (that returns no resultset) against the database specified in the connection string
        /// using a stored procedure and the provided parameters.
        /// </summary>
        /// <remarks>
        /// e.g.:
        ///  int result = StoreProcUpdate("PublishOrders", new SqlParameter("@prodid", 24));
        /// </remarks>
        /// <param name="StoreProcedureName">the name of the stored procedure to be used.)</param>
        /// <param name="CommandParameters">an array of SqlParamters used to execute the groupCommand</param>
        /// <returns>an int representing the number of rows affected by the groupCommand</returns>
        // -------------------------------------------------------------------------------------
        public static int StoreProcUpdate(string StoreProcedureName, params SqlParameter [] CommandParameters)
        {
            int iResult = 0;

            using (SqlConnection conn = new SqlConnection(_connectionString))
            {
                conn.Open( );
                using (SqlTransaction trans = conn.BeginTransaction( ))
                {
                    try
                    {
                        iResult = EvSqlMethods.ExecuteNonQuery(
                            trans,
                            CommandType.StoredProcedure,
                            StoreProcedureName,
                            CommandParameters);
                        trans.Commit( );
                    }
                    catch (Exception Ex)
                    {
                        trans.Rollback( );
                        EventLog.WriteEntry(_eventLogSource, Ex.Message.ToString( ), EventLogEntryType.Error);
                        throw (Ex);
                    }
                }
                return(iResult);
            }
        }//END StoreProcUpdate method