Stored Procedures, Data Readers and Output Parameters

Posts   
 
    
lsberman
User
Posts: 16
Joined: 22-Feb-2006
# Posted on: 17-Mar-2008 16:29:38   

Hi! I have a stored procedure that returns a single result set and the @@ROWCOUNT of the query through an output parameter. I'd like to iterate through the result set using a DataReader. I need the row count BEFORE I start iterating through the result set. Unfortunately, the Get...CallAsQuery method doesn't return output parameters. Is there any way I can achieve my desired result?

Walaa avatar
Walaa
Support Team
Posts: 14950
Joined: 21-Aug-2005
# Posted on: 18-Mar-2008 09:45:13   

Similar thread: http://www.llblgen.com/TinyForum/Messages.aspx?ThreadID=7153

Which LLBLGen are you using? (Designer release date & templateSet date)

lsberman
User
Posts: 16
Joined: 22-Feb-2006
# Posted on: 18-Mar-2008 13:34:33   

Thanks for the quick reply!

I'm using SelfServicing LLBLGen Pro 2.5 (Final), Release Date Feb 4th, 2008.

I tried the suggested workaround but to no avail:

            int itemCount = 0;

            IRetrievalQuery query = RetrievalProcedures.
                GetGetCanTradeBarsCallAsQuery(symbol);

            TypedListDAO dao = new TypedListDAO();

            IDataReader reader = dao.GetAsDataReader(null,
                query, CommandBehavior.CloseConnection);

            SqlParameter itemCountParam =
                query.Parameters[1] as SqlParameter;

            if (itemCountParam.Value != DBNull.Value)
                itemCount = (int)itemCountParam.Value;

            while (reader.Read())
            {
                // Do something here
            }

            reader.Close();
Otis avatar
Otis
LLBLGen Pro Team
Posts: 39614
Joined: 17-Aug-2003
# Posted on: 19-Mar-2008 09:55:34   

Strange, as the datareader execution of the query should fill the output parameter with the value inside the RetrievalQuery. .Parameters returns the parameters collection of the command used. So the output parameter isn't filled with any output value?

Frans Bouma | Lead developer LLBLGen Pro
arschr
User
Posts: 893
Joined: 14-Dec-2003
# Posted on: 19-Mar-2008 13:01:25   

I seem to remember that the output parameter isn't available untill the result set has been iterated. Could be wrong, but you might check that.

Otis avatar
Otis
LLBLGen Pro Team
Posts: 39614
Joined: 17-Aug-2003
# Posted on: 19-Mar-2008 19:11:35   

Now you mention it... it sounds familiar indeed. Still a bit odd though, considering that an ado.net provider always executes 'executereader' also for action calls.

Though that would be a catch 22 for the situation: the rowcount is needed but that's not availble after the rows are read...

Frans Bouma | Lead developer LLBLGen Pro