Wrox Programmer Forums
Go Back   Wrox Programmer Forums > ASP.NET and ASP > ASP.NET 2.0 > ASP.NET 2.0 Basics
|
ASP.NET 2.0 Basics If you are new to ASP or ASP.NET programming with version 2.0, this is the forum to begin asking questions. Please also see the Visual Web Developer 2005 forum.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the ASP.NET 2.0 Basics section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old February 15th, 2010, 04:15 PM
Authorized User
 
Join Date: Jun 2003
Posts: 54
Thanks: 1
Thanked 0 Times in 0 Posts
Default Can't read result of simple stored procedure

I was debugging a complex stored procedure involving dates and not getting a result.

I then modified the procedure to always retuirns an integer = 148. The procedure works on a standalone basis. I still can't read it in my ASP.NET code. My function always returns 0. What am I missing? TIA

stored procedure & code below


Code:
ALTER PROCEDURE [dbo].[procMinIdByDateOutput_B] 
 
( @minid INT =1 OUTPUT) 
AS 
SET @minid = (148)
RETURN @minid
Code:
 
ProtectedFunction getstartid(ByVal startdate AsDate) AsInteger
Dim Conn AsNew SqlConnection(SqlDataSource1.ConnectionString)
Dim Cmd1 AsNew SqlCommand("procMinIdByDateOutput_B", Conn)
Dim minid AsInteger = 1
Cmd1.CommandType = Data.CommandType.StoredProcedure
Dim minidparam AsNew SqlParameter("@minid", Data.SqlDbType.Int)
Cmd1.Parameters.Add(minidparam)
minidparam.Direction = Data.ParameterDirection.Output
Conn.Open()
minid = CType(Cmd1.ExecuteScalar(), Integer)
Conn.Close()
Return minid
EndFunction
 
Old February 15th, 2010, 08:23 PM
Friend of Wrox
 
Join Date: Jun 2008
Posts: 1,649
Thanks: 3
Thanked 141 Times in 140 Posts
Default

When you call ExecuteScalar, ADO.NET is expecting that the SQL that is invoked--whether ad hoc or stored proc--is going to return a one-row, one-column recordset.

So you would need to do:
Code:
ALTER PROCEDURE [dbo].[procMinIdByDateOutput_B] 
 ( ) 
AS 
DECLARE @minid INT
SET @minid = (148) -- or whatever you really do to get this single value
SELECT @minid
The return value is *NOT* used by ExecuteScalar.
 
Old February 16th, 2010, 12:34 PM
Authorized User
 
Join Date: Jun 2003
Posts: 54
Thanks: 1
Thanked 0 Times in 0 Posts
Default That Works

Thank you. That was very helpful





Similar Threads
Thread Thread Starter Forum Replies Last Post
Retrieving a result set from stored procedure 4thhorseman SQL Server 2005 2 October 12th, 2009 10:45 AM
Empty result set from mysql stored procedure talz13 PHP Databases 3 December 28th, 2008 05:58 PM
stored procedure with two result sets joxa83 SQL Server 2000 14 July 18th, 2007 01:03 AM
Simple XSLT Setup w/Strange Result kwilliams XSLT 5 August 5th, 2005 11:47 AM
How to read SQL Result mrideout BOOK: Beginning ASP.NET 1.0 1 October 20th, 2004 01:10 AM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.