When using the SqlDataReader class in .NET 4.0 to return multiple sets of data from a stored procedure, does it transfer ALL the data from SQL Server for ALL the sets from the start - or does it only transfer subsequent sets of data on each call to .NextResult()?
Or to put it another way: If I failed to call .NextResult() would it still go through the process of transferring the data for the 2nd data set?
I have a stored procedure that potentially returns thousands of rows of data, and I would like to be able to split the stored procedure into two parts:
- Data set 1: a scalar value which denotes the number of rows that will be returned
- Data set 2: the actual rows
In an ideal world I would like to be able to call this stored-procedure, and if the scalar value is under a pre-set number then call .NextResult() and then process the rows from the 2nd data set. And if the scalar value is over the pre-set, then not calling .NextResult() will not require the data to be transferred from the SQL Server.
The simple solution is to have two stored procedures (one to return the number of rows, the other to return the rows)... or have a flag on a single stored procedure to return the number of row or actual rows, and call it twice.
Aucun commentaire:
Enregistrer un commentaire