diff --git a/src/System.Data.Jet/JetCommand.cs b/src/System.Data.Jet/JetCommand.cs index bda0cd4..d1938a0 100644 --- a/src/System.Data.Jet/JetCommand.cs +++ b/src/System.Data.Jet/JetCommand.cs @@ -16,7 +16,6 @@ namespace System.Data.Jet private JetTransaction _transaction; private Guid? _lastGuid; - private int? _rowCount; private static readonly Regex _createProcedureExpression = new Regex(@"^\s*create\s*procedure\b", RegexOptions.IgnoreCase); private static readonly Regex _topParameterRegularExpression = new Regex(@"(?<=(?:^|\s)select\s+top\s+)(?:@\w+|\?)(?=\s)", RegexOptions.IgnoreCase); @@ -213,7 +212,7 @@ namespace System.Data.Jet dataReader = new JetDataReader(InnerCommand.ExecuteReader(behavior)); - _rowCount = dataReader.RecordsAffected; + _connection.RowCount = dataReader.RecordsAffected; } return dataReader; @@ -261,11 +260,7 @@ namespace System.Data.Jet if (_selectRowCountRegularExpression.Match(InnerCommand.CommandText) .Success) { - // TODO: Fix exception message. - if (_rowCount == null) - throw new InvalidOperationException("Invalid " + InnerCommand.CommandText + ". Run a DataReader before."); - - return _rowCount.Value; + return _connection.RowCount; } InnerCommand.CommandText = ParseIdentity(InnerCommand.CommandText); @@ -279,9 +274,7 @@ namespace System.Data.Jet InlineTopParameters(); FixParameters(); - _rowCount = InnerCommand.ExecuteNonQuery(); - - return _rowCount.Value; + return _connection.RowCount = InnerCommand.ExecuteNonQuery(); } /// @@ -401,12 +394,9 @@ namespace System.Data.Jet if (_selectRowCountRegularExpression.Match(commandText) .Success) { - if (_rowCount == null) - throw new InvalidOperationException("Invalid " + commandText + ". Run a DataReader before."); - var dataTable = new DataTable("Rowcount"); dataTable.Columns.Add("ROWCOUNT", typeof(int)); - dataTable.Rows.Add(_rowCount.Value); + dataTable.Rows.Add(_connection.RowCount); return new DataTableReader(dataTable); } diff --git a/src/System.Data.Jet/JetConnection.cs b/src/System.Data.Jet/JetConnection.cs index 9c1cdd5..f25d816 100644 --- a/src/System.Data.Jet/JetConnection.cs +++ b/src/System.Data.Jet/JetConnection.cs @@ -18,6 +18,8 @@ namespace System.Data.Jet internal DbConnection InnerConnection { get; private set; } internal JetTransaction ActiveTransaction { get; set; } + + internal int RowCount { get; set; } /// /// Initializes a new instance of the class. @@ -371,6 +373,7 @@ namespace System.Data.Jet JetFactory.InnerFactory); InnerConnection.StateChange += WrappedConnection_StateChange; + RowCount = 0; _state = ConnectionState.Open; OnStateChange(new StateChangeEventArgs(ConnectionState.Closed, ConnectionState.Open)); }