Wrox Programmer Forums

Need to download code?

View our list of code downloads.

Go Back   Wrox Programmer Forums > Visual Basic > VB 6 Visual Basic 6 > VB Databases Basics
Password Reminder
Register
| FAQ | Members List | Calendar | Search | Today's Posts | Mark Forums Read
VB Databases Basics Beginning-level VB coding questions specific to using VB with databases. Issues not specific to database use will be redirected to other forums.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the VB Databases Basics section of the Wrox Programmer to Programmer discussions. This is a community of tens of thousands of software programmers and website developers including Wrox book authors and readers. As a guest, you can read any forum posting. By joining today you can post your own programming questions, respond to other developers’ questions, and eliminate the ads that are displayed to guests. Registration is fast, simple and absolutely free .
DRM-free e-books 300x50
Reply
 
Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old June 23rd, 2003, 03:11 AM
Authorized User
 
Join Date: Jun 2003
Location: Essendon, Victoria, Australia.
Posts: 61
Thanks: 0
Thanked 0 Times in 0 Posts
Default Can i return a recordset in a Stored procedure


   Hey guyz...am using VB6 as a front end to SQL Server project that am doing. I would like to know if its possible to return a Recordset of all the records received after executing the stored procedure..

  Also is there a way i can declare a recordset in SQL Server 7 to be able to return it. I know how to return and pass parameters of single entities in data to and from Stored procedures. i just can't get around to returnig a whole recordset plaese help..

  Begging for assistance!!.

LION OF JUDDAH!
__________________
LION OF JUDDAH!
Reply With Quote
  #2 (permalink)  
Old June 23rd, 2003, 06:34 AM
Friend of Wrox
 
Join Date: Jun 2003
Location: , , United Kingdom.
Posts: 1,212
Thanks: 0
Thanked 1 Time in 1 Post
Default

You don't need any parameters to return a recordset from within a stored procedure - if there is a SELECT statement in there then it will return a recordset.

Assuming you have an ADO Command object to run your stored procedure, then after you've set up the parameters etc, the syntax to get a recordset is just:
Set rs = cmd.Execute
Reply With Quote
  #3 (permalink)  
Old February 1st, 2005, 01:47 PM
Registered User
 
Join Date: Feb 2005
Location: , , .
Posts: 1
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Help please!!!
I am trying to do just that, return a record set in a stored proc and loop throgh in VB.
My stored proc looks like:

CREATE PROCEDURE [dbo].[Students] AS
Select FirstName, LastName, Address From Studetns Order By Name
GO

My code looks like:
    Dim Cmd 'Command object
    Dim Connection

    Set Cmd = Server.CreateObject("ADODB.Command")


    Set Connection = "The connection string goes here"
    Connection.Open

       Set Cmd.ActiveConnection = Connection.Connection
       Cmd.CommandText = "Students"
       Cmd.CommandType = adCmdStoredProc
       Cmd.Parameters.Refresh
    set rs = Cmd.Execute

    Do While Not rs.EOF
        response.write(rs.Fields("FirstName") & ", " & rs.Fields("LastName") & ", " & rs.Fields("Address") )

    loop

I am getting the error: ADODB.Recordset (0x800A0E78)
Operation is not allowed when the object is closed.


Reply With Quote
  #4 (permalink)  
Old April 8th, 2005, 03:08 PM
Registered User
 
Join Date: Apr 2005
Location: Hilliard, FL, USA.
Posts: 1
Thanks: 0
Thanked 0 Times in 0 Posts
Default

I am getting the error: ADODB.Recordset (0x800A0E78)
Operation is not allowed when the object is closed.

With the same VB6 style solution and all I want to do is get the recordcount from the record set object. All attempts to call recSet.Open has been unsuccessful. Please help. Thank you in advance.

jduce
Reply With Quote
  #5 (permalink)  
Old April 10th, 2005, 01:23 PM
Authorized User
 
Join Date: Apr 2005
Location: Johannesburg, , South Africa.
Posts: 16
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Hi

Your recordset is instantiated but not opened.

rs.open strq, cn, adopenreadonly, adopenforwardonly

regards

Helga Anagnostopoulos
Reply With Quote
  #6 (permalink)  
Old April 21st, 2005, 10:15 AM
Registered User
 
Join Date: Feb 2005
Location: Houston, TX, USA.
Posts: 1
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via MSN to maliyasar
Default

There are several resolutions. I hope, they'll help you.

ERROR:
------------------------------------
ADODB.Recordset (0x800A0E78) Operation is not allowed when the object is closed.


RESOLUTION 1: (FOR STORED PROCEDURES)
------------------------------------
SET NOCOUNT ON

BEGIN TRAN

your <SELECT> Query
your <INSERT> Query
your <DELETE> Query
your <UPDATE> Query

COMMIT TRAN

RETURN <VALUE>

OR

<your FINAL SELECT query>



OR RESOLUTION 2: (FOR ASP, VBScript CODE)
--------------------------------------
1. Create a DataEnvironment (DE) command and bind it to the stored procedure.

2. Use the following code to access the return value of the Data Command:

Set DE = Server.CreateObject("DERuntime.DERuntime")
DE.Init(Application("DE"))

DE.Command1 'parm1, parm2, etc. if parameters required

Set objCMD = DE.Commands("Command1")
RetVal = objCMD.Parameters(0)


Have a great one!

The Power of Turks

Reply With Quote
  #7 (permalink)  
Old December 12th, 2006, 03:34 AM
Registered User
 
Join Date: Dec 2006
Location: , , .
Posts: 3
Thanks: 0
Thanked 0 Times in 0 Posts
Default

I am getting the following error while trying to read a recordset:



ADODB.Recordset(0X800A0E78)Operation is not allowed when the object is

closed.
The error happens in the following line after I execute a stored

procedure in SQLSERVER 7:

set rs=Server.CreateObject("ADODB.Recordset")
set cn=Server.CreateObject("ADODB.Connection")
set cmd=Server.CreateObject("ADODB.Command")

cn.connectionstring ="..."
cn.open

cmd.ActiveConnection=cn
cmd.CommandText="getXMLdata"
cmd.CommandType=4

word=CStr(Request.Form("txt1"))
rs.nocount=on
rs.Open "Exec getXMLdata'" & word &"'",cn

While Not rs.EOF <---------line of error!!!!!!
response.Write(rs(0) & "<br>")
rs.MoveNext
wend

rs.close
set rs=nothing


I do not know how to debug this problem.

Please help!!!!

arathy
Reply With Quote
Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

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 Off
HTML code is Off
Trackbacks are Off
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Stored Procedure return value is NULL kshort ASP.NET 2.0 Basics 16 March 14th, 2017 12:45 PM
[Resolved] Get return value from stored procedure snufse ASP.NET 2.0 Basics 1 August 8th, 2008 11:05 AM
Stored Procedure return value dmiles C# 3 December 6th, 2007 05:20 AM
how i use the Stored Procedure return value and ho yoord ADO.NET 5 June 28th, 2004 08:39 AM
Can i return a recordset in a Stored procedure chiefouko SQL Server 2000 1 June 23rd, 2003 06:13 AM



All times are GMT -4. The time now is 06:48 PM.


Powered by vBulletin®
Copyright ©2000 - 2019, Jelsoft Enterprises Ltd.
© 2013 John Wiley & Sons, Inc.