Returning Values from a SP to asp

Ask a Question related to ASP Database, Design and Development.

  1. #1

    Default Returning Values from a SP to asp

    Hi all

    Win 2kpro, sql 2k, vbscrip asp iis 5

    I'm currently doing something along the lines of:

    dim exists
    msExecutedSQL = "sp_memberexists '" & strName & "' "
    lOptions
    set rs = moConnection.execute (msExecutedSQL, ,lOptions)

    exists=false
    if not rs.eof then
    if rs(0) = 1 then
    exists=true
    response.write "exists"
    end if
    end if
    if not exists then
    response.write "NOT exists!!!"
    end if


    MY SP is as follows:
    CREATE PROCEDURE dbo.sp_memberexists @TestName VARCHAR(30)
    AS
    SET NOCOUNT ON
    IF EXISTS (SELECT UserName FROM test WHERE UserName = @TestName)
    select 1
    else
    select 0
    go


    now this works fine... but I've read that using "RETURN 1/0" in the SP
    is better. as it doesn't create a SP.

    how can I change the above asp so I can do something like:

    msExecutedSQL = "sp_memberexists '" & strName & "' "
    if moConnection.execute (msExecutedSQL, ,lOptions) = 1 then
    response.write "exists"
    else
    response.write "dont exists"
    end if

    thanks for any help & tips.

    Al
    Harag Guest

  2. Similar Questions and Discussions

    1. Web Services: Returning unique values from queries
      Hi there, I have been researcing web services and flash database interaction with Coldfusion. I have read a number of tutorials on this support...
    2. Error returning CFHTTP values
      Im trying to parse some html to get all the href values from it. Once I have the href's I try to remove the html tags from them and add the...
    3. Passing and returning values from another script?
      I would like to encrypt textbox provided passwords. I have a script that I found on the web, and it asks that I call the script and provide the...
    4. Stored Procedure not returning values.
      There are two problems: 1. SQL Server returns the "x number of records affected" message that you see in Query Analyzer to the client as a...
    5. [PHP] Returning values from functions
      Hello, This is a reply to an e-mail that you wrote on Wed, 9 Jul 2003 at 23:40, lines prefixed by '>' were originally written by you. You...
  3. #2

    Default Re: Returning Values from a SP to asp

    Harag wrote:
    > Hi all
    >
    > Win 2kpro, sql 2k, vbscrip asp iis 5
    >
    > I'm currently doing something along the lines of:
    >
    > dim exists
    > msExecutedSQL = "sp_memberexists '" & strName & "' "
    > lOptions
    > set rs = moConnection.execute (msExecutedSQL, ,lOptions)
    >
    > exists=false
    > if not rs.eof then
    > if rs(0) = 1 then
    > exists=true
    > response.write "exists"
    > end if
    > end if
    > if not exists then
    > response.write "NOT exists!!!"
    > end if
    >
    >
    > MY SP is as follows:
    > CREATE PROCEDURE dbo.sp_memberexists @TestName VARCHAR(30)
    Don't use "sp_" as your stored procedure prefix unless you are creating a
    system stored procedure. I've seen people use "usp_". I use "np_" because
    "n" is the first letter of my company's name.
    > AS
    > SET NOCOUNT ON
    > IF EXISTS (SELECT UserName FROM test WHERE UserName = @TestName)
    > select 1
    > else
    > select 0
    > go
    >
    >
    > now this works fine... but I've read that using "RETURN 1/0" in the SP
    > is better. as it doesn't create a SP.
    You mean: "it doesn't create a recordset". This is true. It is more
    efficient to pass a single value back to the client than it is to assemble a
    resultset and pass it to the client, which has to transform it to an ADO
    recordset to allow it to be used by the caller.
    >
    > how can I change the above asp so I can do something like:
    >
    > msExecutedSQL = "sp_memberexists '" & strName & "' "
    > if moConnection.execute (msExecutedSQL, ,lOptions) = 1 then
    > response.write "exists"
    > else
    > response.write "dont exists"
    > end if
    >
    > thanks for any help & tips.
    >
    You can't. To use a Return or output parameter (these are two different
    things), you have to use an explicit ADO Command object. I've created a code
    generator that creates the Command object code for you. You can get it at
    [url]http://www.thrasherwebdesign.com/index.asp?pi=links&hp=links.asp&c=&a=clear[/url]

    You'll have the source code, so you can modify it if you want it to do
    anything differently (such as use different variable names for the ADO
    objects).

    Anyways, after the Execute method is called, the first parameter will
    contain the value returned via the Return statement in the SP. So your code
    would look like this"

    <Command object code from code generator>
    If cmd.Parameters(0) = 1 then
    response.write "exists"
    else
    response.write "dont exists"
    end if

    HTH,
    Bob Barrows


    Bob Barrows Guest

Posting Permissions

  • You may not post new threads
  • You may post replies
  • You may not post attachments
  • You may not edit your posts

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139