PC Review


Reply
Thread Tools Rate Thread

Cannot show a resultset produced by a stored procedure

 
 
Yarik
Guest
Posts: n/a
 
      2nd Oct 2007
Hello,

Let's say there is a table named "Test" and the following stored
procedure:

ALTER PROC dbo.ShowTest
AS
SELECT * FROM Test

When I do the following code in Access

Call DoCmd.OpenStoredProcedure("dbo.ShowTest", acViewNormal,
acReadOnly)

everything works as advertised: Access opens the form displaying
whatever records are there in the table Test.

Now, let's say the stored procedure needs to re-create the table from
scratch; for example:

ALTER PROC dbo.ShowTest
AS
DROP TABLE Test
SELECT 'SomeValue' AS SomeField INTO Test
SELECT * FROM Test

In this case, MS Access says that the stored procedure "...did not
return any records..."

Is there any way to make OpenStoredProcedure() able to show the
recordset returned by the last SELECT statement in this stored
procedure?

(Actually, in my very first experiment, the stored procedure declared
a TABLE variable, filled it with records, and at the very end called
SELECT * FROM @TableVariable. In that case, the call to
OpenStoredProcedure produced the same result: no records returned.
Ideally, I would like to find a workaround for that case too, but
something tells me that it's not going to work...)

Any feedback would be greatly appreciated!

Thanks,
Yarik.

 
Reply With Quote
 
 
 
 
Sylvain Lafontaine
Guest
Posts: n/a
 
      2nd Oct 2007
Add the SET NOCOUNT ON statement at the beginning of the SP. By the way,
DoCmd.OpenStoredProcedure is some old and strange stuff, so don't expect any
miracle from using it.

--
Sylvain Lafontaine, ing.
MVP - Technologies Virtual-PC
E-mail: sylvain aei ca (fill the blanks, no spam please)


"Yarik" <(E-Mail Removed)> wrote in message
news:(E-Mail Removed)...
> Hello,
>
> Let's say there is a table named "Test" and the following stored
> procedure:
>
> ALTER PROC dbo.ShowTest
> AS
> SELECT * FROM Test
>
> When I do the following code in Access
>
> Call DoCmd.OpenStoredProcedure("dbo.ShowTest", acViewNormal,
> acReadOnly)
>
> everything works as advertised: Access opens the form displaying
> whatever records are there in the table Test.
>
> Now, let's say the stored procedure needs to re-create the table from
> scratch; for example:
>
> ALTER PROC dbo.ShowTest
> AS
> DROP TABLE Test
> SELECT 'SomeValue' AS SomeField INTO Test
> SELECT * FROM Test
>
> In this case, MS Access says that the stored procedure "...did not
> return any records..."
>
> Is there any way to make OpenStoredProcedure() able to show the
> recordset returned by the last SELECT statement in this stored
> procedure?
>
> (Actually, in my very first experiment, the stored procedure declared
> a TABLE variable, filled it with records, and at the very end called
> SELECT * FROM @TableVariable. In that case, the call to
> OpenStoredProcedure produced the same result: no records returned.
> Ideally, I would like to find a workaround for that case too, but
> something tells me that it's not going to work...)
>
> Any feedback would be greatly appreciated!
>
> Thanks,
> Yarik.
>



 
Reply With Quote
 
Yarik
Guest
Posts: n/a
 
      2nd Oct 2007
On Oct 1, 8:37 pm, "Sylvain Lafontaine" <sylvain aei ca (fill the
blanks, no spam please)> wrote:
> Add the SET NOCOUNT ON statement at the beginning of the SP.


Wow, works like a charm! Even with a tabular variable!!

This was the quickest and most to-the-point answer I've received in
news in a year! Thank you a lot, Sylvain!

> By the way,
> DoCmd.OpenStoredProcedure is some old and strange stuff, so don't expect any
> miracle from using it.


Sure. Thanks for the advice!

Actually, we don't like to use neither of DoCmd's Open...() methods.
Even OpenForm() :-). As for OpenStoredProcedure, we use it only to
implement cheap-and-dirty reports, which are often requested by the
users on a whim and do not "survive" for too long (either get dumped
after some time or get replaced by more human-friendly, more complex
interactive reports).



 
Reply With Quote
 
 
 
Reply

Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Open parameterised stored proc as a resultset in a window sebt Microsoft Access ADP SQL Server 2 27th Apr 2006 11:06 AM
Returning a resultset from Oracle Stored Procedure using ADO (VBA) =?Utf-8?B?bWFyeQ==?= Microsoft Excel Programming 0 30th Dec 2005 05:26 PM
Using OleDBDataReader (C#) to retrieve stored proc return code and then resultset dshiel@flexicom.com Microsoft ADO .NET 3 2nd Apr 2004 06:56 PM
Calling a Stored Procedure in a Stored Procedure Group DJM Microsoft ADO .NET 1 21st Jan 2004 08:03 PM
How do I show the results of a stored procedure in a datagrid? Jim Microsoft VB .NET 6 9th Jan 2004 09:21 PM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 09:07 AM.