Wrox Programmer Forums
Go Back   Wrox Programmer Forums > Visual Basic > VB 6 Visual Basic 6 > VB Databases Basics
|
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 software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old June 23rd, 2003, 03:11 AM
Authorized User
 
Join Date: Jun 2003
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!
 
Old June 23rd, 2003, 06:34 AM
Friend of Wrox
 
Join Date: Jun 2003
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
 
Old February 1st, 2005, 01:47 PM
Registered User
 
Join Date: Feb 2005
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.


 
Old April 8th, 2005, 03:08 PM
Registered User
 
Join Date: Apr 2005
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
 
Old April 10th, 2005, 01:23 PM
Authorized User
 
Join Date: Apr 2005
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
 
Old April 21st, 2005, 10:15 AM
Registered User
 
Join Date: Feb 2005
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

 
Old December 12th, 2006, 03:34 AM
Registered User
 
Join Date: Dec 2006
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





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





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.