Web Wiz - Green Windows Web Hosting

  New Posts New Posts RSS Feed - Stored procedure error -- please help
  FAQ FAQ  Forum Search   Events   Register Register  Login Login

Stored procedure error -- please help

 Post Reply Post Reply
Author
stephen View Drop Down
Newbie
Newbie


Joined: 23 August 2002
Location: United Kingdom
Status: Offline
Points: 33
Post Options Post Options   Thanks (0) Thanks(0)   Quote stephen Quote  Post ReplyReply Direct Link To This Post Topic: Stored procedure error -- please help
    Posted: 27 May 2004 at 12:47pm

I am trying to get a returned value from the stored procedure below

CREATE PROC insert_and_return_id
(
    @parameter1 varchar,
    @parameter2 varchar
 
)
AS
DECLARE @newID int
SELECT @newID = 0

INSERT INTO tbltest (field1, field2)
VALUES (@parameter1, @parameter2)

 IF(@@ROWCOUNT > 0)
BEGIN
    SELECT @newID = @@IDENTITY
END

RETURN @newID
GO

___________________________

My asp Code looks like this

___________________________

Function InserTest(value1, value2)
 Dim objConn, objRs, objCmd

    '  Create a connection to the database
    Set objConn = Server.CreateObject("ADODB.Connection")
   objConn.open "DSN=" & CONNECTION_STRING

    ' Create the query command
    Set objCmd = Server.CreateObject("ADODB.Command")
    Set objCmd.ActiveConnection = objConn
    objCmd.CommandText = "insert_and_return_id"
    objCmd.CommandType = adCmdStoredProc
 ' Create the parameter for output and returned valueand populate it
    objCmd.Parameters.Append objCmd.CreateParameter("parameter1", adVarChar, adParamInput, 255, value1)
 objCmd.Parameters.Append objCmd.CreateParameter("parameter2", adVarChar, adParamInput, 255, value2)
    objCmd.Parameters.Append objCmd.CreateParameter("newID", adInteger, adParamReturnValue, 4)
 
 objCmd.Execute objCmd0
    response.write objCmd.Parameters("newID")
 'objCmd.Close
End Function

 

And I get the following ASP Error

Error Type:
Microsoft OLE DB Provider for ODBC Drivers (0x80040E14)
[Microsoft][ODBC SQL Server Driver][SQL Server]Procedure or function insert_and_return_id has too many arguments specified.
/netwasp/tester.asp, line 62

 

I only just started to use sp's hence it might be something really simple, Can anyone help, cheers?

 


Back to Top
Mart View Drop Down
Senior Member
Senior Member
Avatar

Joined: 30 November 2002
Status: Offline
Points: 2304
Post Options Post Options   Thanks (0) Thanks(0)   Quote Mart Quote  Post ReplyReply Direct Link To This Post Posted: 27 May 2004 at 2:56pm
Well you have only set 2 parameters in your sp (parameter1 and parameter2) but you have supplied an extra one (newID) in the ASP script - either edit your sp or remove that parameter
Back to Top
psycotik View Drop Down
Groupie
Groupie


Joined: 27 November 2003
Status: Offline
Points: 73
Post Options Post Options   Thanks (0) Thanks(0)   Quote psycotik Quote  Post ReplyReply Direct Link To This Post Posted: 01 June 2004 at 8:57am

Another way of doing it might be:

CREATE PROC insert_and_return_id (
  @parameter1 varchar,
  @parameter2 varchar,
  @newID int = 0 OUTPUT 
)
AS

INSERT INTO tbltest (field1, field2)
VALUES (@parameter1, @parameter2)

IF(@@ROWCOUNT > 0)
BEGIN
    SELECT @newID = @@IDENTITY
END

GO

Then in your asp:

Set objCmd = Server.CreateObject("ADODB.Command")
    Set objCmd.ActiveConnection = objConn
    objCmd.CommandText = "insert_and_return_id"
    objCmd.CommandType = adCmdStoredProc
 ' Create the parameter for output and returned valueand populate it
    objCmd.Parameters.Append objCmd.CreateParameter("parameter1", adVarChar, adParamInput, 255, value1)
 objCmd.Parameters.Append objCmd.CreateParameter("parameter2", adVarChar, adParamInput, 255, value2)
 
 objCmd.Execute objCmd0
    response.write objCmd.Parameters("@newID")
 'objCmd.Close

ps. there might by a slight error in my syntax as i didnt test this

Back to Top
 Post Reply Post Reply

Forum Jump Forum Permissions View Drop Down

Forum Software by Web Wiz Forums® version 12.08
Copyright ©2001-2026 Web Wiz Ltd.


Become a Fan on Facebook Follow us on X Connect with us on LinkedIn Web Wiz Blogs
About Web Wiz | Contact Web Wiz | Terms & Conditions | Cookies | Privacy Notice

Web Wiz is the trading name of Web Wiz Ltd. Company registration No. 05977755. Registered in England and Wales.
Registered office: Web Wiz Ltd, Unit 18, The Glenmore Centre, Fancy Road, Poole, Dorset, BH12 4FB, UK.

Prices exclude VAT at 20% unless otherwise stated. VAT No. GB988999105 - $, € prices shown as a guideline only.

Copyright ©2001-2026 Web Wiz Ltd. All rights reserved.