According to MSDN article OdbcCommand.ExecuteNonQuery Method
It be defined as below:
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.
(No support SELECT statments ?)
And this is my sample code in C#.net(my database is PostgreSQL):
odbcCommand.CommandText = "SELECT key_id FROM sometable WHERE p1 = 1";
Console.WriteLine(odbcCommand.ExecuteNonQuery());
It really works. It can return the count of select rows correctly.
But when I search some articles in stackoverflow, ex:( ExecuteNonQuery() ),( ExecuteNonQuery for SELECT sql statement returning no rows ).
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?)
So,my question is "Can I continue using ExecuteNonQuery() to get count ?(Although it works)"