/// <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); }
/// <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); }
private void DieQueryError() { MapiFactory.DieQueryError(_connHandle, _queryHandle); }