title: Using ExecuteNonQuery() method to get count of select rows OR NOT ? In C#.net
body: <p>According to MSDN article <a href="http://msdn.microsoft.com/en-us//library/system.data.odbc.odbccommand.executenonquery(v=vs.110).aspx" rel="nofollow noreferrer">OdbcCommand.ExecuteNonQuery Method</a></p>
  
  <p>It be defined as below:</p>
  
  <blockquote>
    <p>For UPDATE, INSERT, and DELETE statements, the return value is the number of rows affected by the command. For all other types of statements, the return value is -1.</p>
  </blockquote>
  
  <p>(No support SELECT statments ?)</p>
  
  <p>And this is my sample code in C#.net(my database is PostgreSQL):</p>
  
  <pre><code>odbcCommand.CommandText = "SELECT key_id FROM sometable WHERE p1 = 1";
  Console.WriteLine(odbcCommand.ExecuteNonQuery());
  </code></pre>
  
  <p>It really works. It can return the count of select rows correctly.</p>
  
  <p>But when I search some articles in stackoverflow, ex:( <a href="https://stackoverflow.com/questions/5349114/executenonquery">ExecuteNonQuery()</a> ),( <a href="https://stackoverflow.com/questions/4269548/executenonquery-for-select-sql-statement-returning-no-rows">ExecuteNonQuery for SELECT sql statement returning no rows</a> ).</p>
  
  <p>They do not recommend use ExecuteNonQuery() to get count of select rows,but recommend use ExecuteReader and loop to get count. (It seems that ExecuteNonQuery() sometimes will get wrong value?)</p>
  
  <p>So,my question is "Can I continue using ExecuteNonQuery() to get count ?(Although it works)"</p>