retrieving row count from query

  • Thread starter Thread starter VMI
  • Start date Start date
V

VMI

How can I execute a "Select" query from C# so that it only returns an
integer with the amount of rows that the actual query is supposed to return?
I don't want the whole result set.

Thanks.
 
Thanks, it worked, in conjunction with ExecuteScalar .
I read that with the data reader you would need to bring the resultset back
to the application.
 
VMI said:
Thanks, it worked, in conjunction with ExecuteScalar .
I read that with the data reader you would need to bring the resultset back
to the application.

Well, yes and no - you'd bring "the resultset" back, but that resultset
would be just a single row with a single column, because the query
doesn't retrieve the rows, only the count.
 
--> if I want to get both the "resultset" and count affected rows. How can?
I must fetch to the end row and count ? another way?
 
Dean L. Howen said:
--> if I want to get both the "resultset" and count affected rows. How can?
I must fetch to the end row and count ? another way?

No, there basically isn't another way. I asked the same thing in a Java
newsgroup a long time ago, and was shocked by the answer :(

Any time you ask for a number of rows, that information can be out of
date by the time you get the answer back. You could do a query which
returned two resultsets, one containing just the count and one
containing the actual data - but you need to be ready for there to be
more or fewer rows in the actual data than the count suggests...
 
Back
Top