[thelist] .NET: Can't get Stored Proc to Return a Value
Casey Crookston
caseyb at thecrookstons.com
Tue Feb 12 22:03:21 CST 2008
Hi,
I'm having trouble getting a stored procedure to return a single integer
value. Here's a short version:
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
set ANSI_NULLS ON
set QUOTED_IDENTIFIER ON
GO
ALTER PROCEDURE [dbo].[Perm_Import_CJ]
AS
/* bunch of stuff removed */
DECLARE @NoCategory int
SELECT @NoCategory = COUNT(*) FROM table CategoryID IS NULL
/* print @NoCategory */
RETURN @NoCategory
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
If I uncomment "print @NoCategory" it prints exactly the number it's
supposed to, so there is no problem with any of the queries in the stored
procedure. Then, in the code, this is what 'm doing:
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Dim dbConn As New
SqlConnection(WebConfigurationManager.ConnectionStrings("ConnectionName").ConnectionString)
Dim cmd As New SqlCommand("StoredProc", dbConn)
cmd.CommandType = CommandType.StoredProcedure
dbConn.Open()
Dim intNoCategory As Integer = CInt(cmd.ExecuteScalar())
dbConn.Close()
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
But, intNoCategory ALWAYS returns a zero.
Not sure what I am doing wrong. Thanks in advance for any help!
Casey
More information about the thelist
mailing list