Hi,

I want to know how to get the total of rows (of myRead) after I executed:

myRead = myCommnd.ExecuteReader();

The only way I get it is using a loop, but exist a command for that?

Thanks!

Why are you not uisng the Count() function in your SQL statement ? or execute the query in Adapter and then fill the Datatable and you will goood to go...

Hi,

I want to know how to get the total of rows (of myRead) after I executed:

myRead = myCommnd.ExecuteReader();

The only way I get it is using a loop, but exist a command for that?

Thanks!

Why are you not uisng the Count() function in your SQL statement ? or execute the query in Adapter and then fill the Datatable and you will goood to go...

I am copying more than 1M of rows. In other tutorial I read that Count() probably will not be fast enough...

Can you explain to me a little bit more about execute the query in Adapter?

BTW I forget to say that I am using now BulkCopy and SqlDataAdapter so I can use the NotifyAfter...but I want to know how to get the total of rows to show the percent of progress copying.

Thanks!

You can't. The SqlDataReader is read forward only. The RecordsAffected property is only accurate after calling Close. If you must have a count, then use the Count function as Rohand said. If the query is using indexed fields in the where clause for the count, it will be fast enough.

Can you please clarify.
You want to get the count of rows for a query, before doing the query, so you can accurately report the query progress?

Can you please clarify.
You want to get the count of rows for a query, before doing the query, so you can accurately report the query progress?

Before storing the data to a another table, so as you said to report the query saving progress.
But I already know how to do this. I just want a method to know the total of rows without using a loop.

This article has been dead for over six months. Start a new discussion instead.