Link to home
Start Free TrialLog in
Avatar of hidrau
hidrauFlag for Brazil

asked on

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

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
Avatar of Big Monty
Big Monty
Flag of United States of America image

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
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
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

Avatar of hidrau

ASKER

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
ASKER CERTIFIED SOLUTION
Avatar of Big Monty
Big Monty
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of hidrau

ASKER

thanks