IDataReader - Any way to get full lines?

Is there a way to get the total number of rows returned from an SQL query (from IDataReader) before repeating through rows using reader.Read(); ?

+6
source share
4 answers

Not.

IDataReader - a simple view only for a direct set of results; he cannot get the bill.

+9
source

No, the datareader will not return the account first. However, if you need to do this, use two queries that return multiple result sets.

for example in SQL Server:

sql = "Choose count (*) from A; select * from A;"

Iterate result sets. Use the datareader in the second result set.

The database server should be able to do this fairly quickly if it uses the appropriate indexes.

+3
source

Well, for the past date, but there is a way that worked for me, it took some time, because I suck in the wording of my search queries.

 dbCommand.Connection.Open(); //dbReader = dbCommand.ExecuteReader(); I left this here to show not to do the read searchCount = dbCommand.ExecuteScalar(); // this line returns the value count // from my tests on my reader it works perfectly 
+3
source

The number of lines calculated only when reading the DataReader, but I did not get it, why do you want to know the number of lines before reading it.

0
source

Source: https://habr.com/ru/post/892991/


All Articles