/// <summary>
        /// Closes the <see cref="T:System.Data.IDataReader"/> Object.
        /// </summary>
        public void Close()
        {
            MapiFactory.CloseQueryHandle(_queryHandle);
            MapiFactory.CloseConnectionHandle(_connHandle);

            IsClosed = true;
        }
Example #2
0
        /// <summary>
        ///     Executes an SQL statement against the Connection object of a .NET Framework data provider, and returns the number
        ///     of rows affected.
        /// </summary>
        /// <returns>
        ///     The number of rows affected.
        /// </returns>
        /// <exception cref="T:System.InvalidOperationException">The connection does not exist.-or- The connection is not open. </exception>
        public int ExecuteNonQuery()
        {
            var connHandle  = _connection.GetConnectionHandle();
            var queryHandle = MapiFactory.GetQueryHandle(connHandle, CommandText);

            var rowsAffected = MapiLib.MapiRowsAffected(queryHandle).To <int>();

            MapiFactory.DieQueryError(connHandle, queryHandle);

            MapiFactory.CloseQueryHandle(queryHandle);

            return(rowsAffected);
        }
Example #3
0
        /// <summary>
        ///     Executes the query, and returns the first column of the first row in the resultset returned by the query. Extra
        ///     columns or rows are ignored.
        /// </summary>
        /// <returns>
        ///     The first column of the first row in the resultset.
        /// </returns>
        public object ExecuteScalar()
        {
            var connHandle  = _connection.GetConnectionHandle();
            var queryHandle = MapiFactory.GetQueryHandle(connHandle, CommandText);

            object result = null;

            if (MapiLib.MapiFetchRow(queryHandle) > 0)
            {
                MapiFactory.DieQueryError(connHandle, queryHandle);

                result = MapiLib.MapiFetchField(queryHandle, 0);
                MapiFactory.DieQueryError(connHandle, queryHandle);
            }

            MapiFactory.CloseQueryHandle(queryHandle);

            return(result);
        }