Azavea.Open.DAO.SQL.SqlConnectionUtilities.XSafeIntQuery C# (CSharp) Method

XSafeIntQuery() public static method

Similar to the "XSafeQuery" method, except this executes a query that returns a single integer (such as SELECT COUNT).
public static XSafeIntQuery ( AbstractSqlConnectionDescriptor connDesc, SqlTransaction transaction, string sql, IEnumerable sqlParams ) : int
connDesc AbstractSqlConnectionDescriptor The database connection descriptor. This is used both as /// a key for caching connections/commands as well as for /// getting the actual database connection the first time.
transaction SqlTransaction The transaction to do this as part of.
sql string The SQL query to execute.
sqlParams IEnumerable A list of objects to use as parameters /// to the SQL statement. The list may be /// null if there are no parameters.
return int
        public static int XSafeIntQuery(AbstractSqlConnectionDescriptor connDesc,
            SqlTransaction transaction, string sql, IEnumerable sqlParams)
        {
            int retVal;
            object retObj = XSafeScalarQuery(connDesc, transaction, sql, sqlParams);
            try
            {
                if (retObj == null)
                {
                    throw new NullReferenceException(
                        "The sql query should have returned an int, but returned null instead.");
                }
                retVal = Convert.ToInt32(retObj);
            }
            catch (Exception e)
            {
                throw new UnableToProcessSqlResultsException("Result was not numeric. ",
                                                             connDesc, sql, sqlParams, e);
            }
            return retVal;
        }

Same methods

SqlConnectionUtilities::XSafeIntQuery ( AbstractSqlConnectionDescriptor connDesc, string sql, IEnumerable sqlParams ) : int