title: SqlDataReader.RecordsAffected incorrectly returns -1 when using INSERT...OUTPUT.inserted
body: <p>We rely on <a href="http://msdn.microsoft.com/en-us/library/system.data.sqlclient.sqldatareader.recordsaffected.aspx" rel="nofollow"><code>SqlDataReader.RecordsAffected</code></a> to count the number of rows modified by a stored procedure.  </p>
  
  <p>MSDN states its definition as:</p>
  
  <blockquote>
    <p>The number of rows changed, inserted, or deleted; 0 if no rows were affected or the statement failed; and -1 for SELECT statements... The value of this property is cumulative. For example, if two records are inserted in batch mode, the value of RecordsAffected will be two.</p>
  </blockquote>
  
  <p>It appears that ADO.NET misinterprets any statement using the <a href="http://msdn.microsoft.com/en-us/library/ms177564.aspx" rel="nofollow"><code>OUTPUT</code> clause</a> as a <code>SELECT</code> statement and returns -1 for <code>RecordsAffected</code> instead of the actual count of modified rows. </p>
  
  <p>For example:</p>
  
  <pre class="lang-sql prettyprint-override"><code>CREATE TABLE dbo.example (
        a INT
      , b VARCHAR(10)
      , c DATETIME2(3)    DEFAULT(SYSUTCDATETIME())
  );
  
  INSERT INTO dbo.example (
       a
     , b
  )
  OUTPUT inserted.c -- Comment out this line and RecordsAffected goes from -1 to 1.
  VALUES (
       1
     , 'blah'
  );
  </code></pre>
  
  <p>Is this ADO.NET behavior by design or by error?</p>
  
  <p>For the record, we plan to change our code to explicitly capture counts of modified rows using <code>@@ROWCOUNT</code> and return them as <code>OUTPUT</code> parameters in our stored procedures.</p>