Stored Proc not Outputting

D

David Lozzi

Hello,

I have a proc as displayed below. When I try to run it from ASP.NET I get an
error.

CREATE PROCEDURE [dbo].[cp_AddSession]
@SID as int,
@EID as int,
@DID as int,
@StartTime as varchar(10),
@Duration as int,
@Title as varchar(50),
@Location as varchar(50),
@Description as text,
@RegForm as varchar(50),
@SessID int OUTPUT
AS


INSERT INTO tblSessions
(intEID, intDay, strStartTime, intDuration, strTitle, strDescription,
strRoomLocation, strRegistrationForm)
VALUES
(@EID, @DID, @StartTime, @Duration, @Title, @Description, @Location,
@RegForm)

SELECT @SessID = @@IDENTITY
GO


Error: Procedure 'cp_AddSession' expects parameter '@SessID', which was not
supplied.


Thanks for the help!!
 
K

Karl Seguin

Also, if you are only returning 1 parameters, I'd use ExecuteScalar and
simply select the value ala:

object o = command.ExecuteScalar();
if (o != null && o!= DBNull.Value)
{
return Int32.Parse(o);
}

and simply do SELECT @@IDENTITY in your stored procedure.

This will return 1 value (the identity), which is exactly what ExecuteScalar
is there to handle.

On a side note, in SQL Server 2000, use SCOPE_IDENTITY() instead of
@@IDENTITY, else you'll eventually run into trouble:
http://weblogs.asp.net/rosherove/archive/2003/11/13/37217.aspx

Karl

--
MY ASP.Net tutorials
http://www.openmymind.net/
http://openmymind.net/redirector.aspx?documentId=51 - Learn about AJAX!



Peter Rilling said:
Did you supply the parameter in your code?

David Lozzi said:
Hello,

I have a proc as displayed below. When I try to run it from ASP.NET I get
an error.

CREATE PROCEDURE [dbo].[cp_AddSession]
@SID as int,
@EID as int,
@DID as int,
@StartTime as varchar(10),
@Duration as int,
@Title as varchar(50),
@Location as varchar(50),
@Description as text,
@RegForm as varchar(50),
@SessID int OUTPUT
AS


INSERT INTO tblSessions
(intEID, intDay, strStartTime, intDuration, strTitle, strDescription,
strRoomLocation, strRegistrationForm)
VALUES
(@EID, @DID, @StartTime, @Duration, @Title, @Description, @Location,
@RegForm)

SELECT @SessID = @@IDENTITY
GO


Error: Procedure 'cp_AddSession' expects parameter '@SessID', which was
not supplied.


Thanks for the help!!
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,744
Messages
2,569,483
Members
44,903
Latest member
orderPeak8CBDGummies

Latest Threads

Top