Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

Pass Return Code to ASP Page

Posted on 2003-10-23
5
Medium Priority
?
265 Views
Last Modified: 2012-06-21
below is my stored procedure. what i want to do is to return the value 1 or 0 to an asp page. How can i pass the value 1 or 0 to an ASP page?

CREATE PROCEDURE DoesRecordExist
   @pid int
AS

IF EXISTS(SELECT * FROM BasketItems WHERE ProductID = @pid)
   RETURN (1)
ELSE
   RETURN (0)
GO

thanks
0
Comment
Question by:jamaje
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
5 Comments
 
LVL 3

Accepted Solution

by:
SQLMaster earned 200 total points
ID: 9606439
Hi,

Instead of using a stored procedure, the best way will be to use a User Defined Function and catch the return value in the  recordset that will be passed to ASP page

Thanks
0
 
LVL 75

Assisted Solution

by:Anthony Perkins
Anthony Perkins earned 200 total points
ID: 9606931
Something like this (untested):
Dim cmd
Set cmd = Server.CreateObject("ADODB.Command")
With cmd
   .ActiveConnection = "your connection string goes here"
   .CommandText = "DoesRecordExist"
   .CommandType = adCmdStoredProc
   .Parameters.Append .CreateParameter("@RETURN_VALUE", adInteger, adParamReturnValue, 0)
   .Parameters.Append .CreateParameter("@pid", adInteger, adParamInput, 0,YourInputValueGoesHere)
   .Execute , , adExecuteNoRecords
   Response.Write .Parameters("@RETURN_VALUE").Value
End With
Set cmd = Nothing

Make sure you are including all the ADO constants (use adovbs.inc) or replace them with their corresponding values.

Anthony
0
 

Expert Comment

by:fromapu
ID: 9618947
hi
Let me modify the stored procedure a bit.

CREATE PROCEDURE DoesRecordExist
   @pid int,
   @Return Smallint Output
AS

IF EXISTS(SELECT * FROM BasketItems WHERE ProductID = @pid)
  Select @RETURN = 1
ELSE
   Select @RETURN = 0
GO

Then the ASP code:

dim cmd, prmPid, prmReturn, pid
pid = request("pid")
Set cmd = Server.createobject("ADODB.Command")
With cmd
         Set .activeconnection = "Your Connection object's name"
         .commandType = "adcmdStoredProc"
         .CommandText = "DoesRecordExist"
         
         Set prmPID = .CreateParameter("@PID",adInteger, adParamInput,4,pid
          .Parameters.Append prmPID

         Set prmReturn= .CreateParameter("@Return",adSmallint, adParamOutput,2)
          .Parameters.Append prmReturn

          .Execute

          Response.write .Parameters("@Return").Value
End With

I think this would work
Bye
fromapu
0

Featured Post

Get your Conversational Ransomware Defense e‑book

This e-book gives you an insight into the ransomware threat and reviews the fundamentals of top-notch ransomware preparedness and recovery. To help you protect yourself and your organization. The initial infection may be inevitable, so the best protection is to be fully prepared.

Question has a verified solution.

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

Ever needed a SQL 2008 Database replicated/mirrored/log shipped on another server but you can't take the downtime inflicted by initial snapshot or disconnect while T-logs are restored or mirror applied? You can use SQL Server Initialize from Backup…
This article shows gives you an overview on SQL Server 2016 row level security. You will also get to know the usages of row-level-security and how it works
Familiarize people with the process of utilizing SQL Server functions from within Microsoft Access. Microsoft Access is a very powerful client/server development tool. One of the SQL Server objects that you can interact with from within Microsoft Ac…
Via a live example, show how to backup a database, simulate a failure backup the tail of the database transaction log and perform the restore.

618 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