title: How can I get the # of rows affected by a statement using ADO with JavaScript?
body: <p>I'm using <a href="http://msdn.microsoft.com/en-us/library/ms675532(VS.85).aspx" rel="nofollow noreferrer">ADO</a> in a JScript (Microsoft JavaScript dialect) Windows Scripting Host script to update a SQL Server table. I'd like to get the number of rows affected by the update in the script, but JavaScript doesn't have pass-by-reference and so I can't do the usual thing where I receive the records affected from the <a href="http://msdn.microsoft.com/en-us/library/ms681559(VS.85).aspx" rel="nofollow noreferrer"><code>Command#Execute</code></a> function's <em>RecordsAffected</em> argument. So I'm looking for the best way to get that info.</p>
  
  <p>For reasons not related directly to this query, I want to avoid using a stored procedure for this although I realize that that <em>would</em> work (I'd just return <code>@@rowcount</code> out of the SP). I'm trying to find a reliable but simple non-SP means of doing it.</p>
  
  <p>I looked around and found this syntax for the statement:</p>
  
  <pre><code>UPDATE MyTable
  SET MyColumn = (blah blah blah)
  WHERE (blah blah blah) ;
  SELECT @@rowcount as 'RowsAffected'
  </code></pre>
  
  <p>...which sends me back a one-row <code>ResultSet</code> containing the count. That does seem to work, and in my limited testing seems to work correctly (I don't get the wrong count when other operations are also happening, etc.), but it seems...kludgy for some reason.</p>
  
  <p>Is that the best way to do it, given the perhaps-unreasonable constraints I've listed? Cross-platform solutions are not required (welcome, though, as always), it can be Microsoft SQL Server-specific (2005+).</p>
  
  <p>Thanks in advance.</p>