Solved

Run a store procedure and get the select result to be showed - how?

Posted on 2013-01-15
6
263 Views
Last Modified: 2013-01-30
Hello guys

I have a store procedure and I want to run it, but at the end of my store procedure, there is a query that show all the rows.

How to run the store procedure and get the rows to display it in asp?

thanks
0
Comment
Question by:hidrau
  • 3
  • 2
6 Comments
 
LVL 33

Expert Comment

by:Big Monty
ID: 38780082
just assign to a recordset like you would with a normal sql satatement:

sql = "exec storedProcedure 1, 2, 3"
set rs = conn.Execute( sql )

do while not rs.eof
    '--display data
    rs.MoveNext
loop
0
 
LVL 33

Expert Comment

by:Big Monty
ID: 38780087
or if you're using a command object, prepare the command and use the following to put the data into a recordset:

rs.Open commandObject
0
 
LVL 52

Expert Comment

by:Scott Fell, EE MVE
ID: 38781407
If you have a stored procedure in your sql database.  You will create a function to call the stored procedure and in your asp code call the function to get the value.  Below is what I use to get the most recent added record.  But you can loop through as suggested above to get all or part of the rows.  
<%
' include adovbs file
theID=AddNewThing("Tonka Truck")
response.write theID


Function AddNewThing(widget)

Set cmd = Server.CreateObject("ADODB.Command")
With cmd

   	.ActiveConnection = connMyConnection
    .CommandType = adCmdStoredProc
   	.CommandText = "addNewThing" ' name of your stored procedure
   
   	.Parameters.Append .CreateParameter("@newThing",adVarWChar, adParamInput, 50)
   	.Parameters("@newThing") = widget

   set rsName = .Execute
End With

 AddNewThing= rs(0) 
 
set cmd = nothing
set rs = nothing

end Function

%>

Open in new window

0
Free Tool: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

 
LVL 1

Author Comment

by:hidrau
ID: 38782112
Hello

I tried this
 Sql = " EXECUTE STP_CRMPOSITIVACAO " & Clie & ",-2 "
 Call abre_conexao_hidrau   ' open conection
 Set Rs = Server.CreateObject("ADODB.RecordSet") 
 Rs.ActiveConnection = CnxHidrau


I tried this way:  Rs.Open CnxHidrau.Execute(Sql)

I tried this way: set Rs = CnxHidrau.Execute(Sql)

 If Not Rs.Eof Then 
 End if

Open in new window


When I run my code I getting the error here "
 If Not Rs.Eof Then"

The message is:

Operations doesn't allow when the object is closed
0
 
LVL 33

Accepted Solution

by:
Big Monty earned 500 total points
ID: 38782757
try this:

Sql = " EXECUTE STP_CRMPOSITIVACAO " & Clie & ",-2 "

 Call abre_conexao_hidrau   ' open conection

 Set Rs = Server.CreateObject("ADODB.RecordSet")

set Rs = CnxHidrau.Execute(Sql)

 If Not Rs.Eof Then
 End if

if it doesnt work, your 2nd line isn't returning a connection object.
0
 
LVL 1

Author Closing Comment

by:hidrau
ID: 38834941
thanks
0

Featured Post

Networking for the Cloud Era

Join Microsoft and Riverbed for a discussion and demonstration of enhancements to SteelConnect:
-One-click orchestration and cloud connectivity in Azure environments
-Tight integration of SD-WAN and WAN optimization capabilities
-Scalability and resiliency equal to a data center

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
ASP Sessions Being Cleared/Modified 6 87
Update field in order 21 148
Summernote and form validation 10 181
JS does not refresh 6 30
Hello, all! I just recently started using Microsoft's IIS 7.5 within Windows 7, as I just downloaded and installed the 90 day trial of Windows 7. (Got to love Microsoft for allowing 90 days) The main reason for downloading and testing Windows 7 is t…
This demonstration started out as a follow up to some recently posted questions on the subject of logging in: http://www.experts-exchange.com/Programming/Languages/Scripting/JavaScript/Q_28634665.html and http://www.experts-exchange.com/Programming/…
With Secure Portal Encryption, the recipient is sent a link to their email address directing them to the email laundry delivery page. From there, the recipient will be required to enter a user name and password to enter the page. Once the recipient …

840 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question