예제 #1
0
        /// <summary>
        /// Return the value of the specified field.
        /// </summary>
        /// <returns>
        /// The <see cref="T:System.Object"/> which will contain the field value upon return.
        /// </returns>
        /// <param name="i">The index of the field to find. </param><exception cref="T:System.IndexOutOfRangeException">The index passed was outside the range of 0 through <see cref="P:System.Data.IDataRecord.FieldCount"/>. </exception>
        public object GetValue(int i)
        {
            var value = MapiLib.MapiFetchField(_queryHandle, i);

            DieQueryError();

            return(value);
        }
예제 #2
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);
        }