Wrox Programmer Forums
Go Back   Wrox Programmer Forums > .NET > Other .NET > ADO.NET
ADO.NET For discussion about ADO.NET.  Topics such as question regarding the System.Data namespace are appropriate.  Questions specific to a particular application should be posted in a forum specific to the application .
Welcome to the p2p.wrox.com Forums.

You are currently viewing the ADO.NET 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 December 8th, 2004, 04:14 AM
Authorized User
Join Date: Dec 2004
Posts: 13
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via AIM to kvanchi
Default stored procedure

i want to return a value from stored procedure
to code behind in vb
how can do that
can any one help me with stored procedure
and how to get that return value in vb

Old December 9th, 2004, 07:27 AM
Friend of Wrox
Join Date: Jul 2004
Posts: 623
Thanks: 0
Thanked 1 Time in 1 Post

consider this simple SP,
Create Procedure GetAuthorsCount
Return ( Slect Count(*) From Authors )
below code use that SP and returns the result as a return value,
<%@ Import Namespace="System.Data.SqlClient" %>
<%@ Import Namespace="System.Data" %>
Dim conPubs As SqlConnection
Dim cmdAuthorCount As SqlCommand
Dim parmReturnValue As SqlParameter
Dim intAuthorCount As Integer
conPubs = New SqlConnection( "Server=localhost;uid=sa;pwd=secret;database=pubs" )
cmdAuthorCount = New SqlCommand( "GetAuthorCount", conPubs )
cmdAuthorCount.CommandType = CommandType.StoredProcedure
parmReturnValue = cmdAuthorCount.Parameters.Add( "ReturnValue", SqlDbType.Int )
parmReturnValue.Direction = ParameterDirection.ReturnValue
intAuthorCount = cmdAuthorCount.Parameters( "ReturnValue" ).Value
There are <%=intAuthorCount%> records in the Authors table
ofcource,if I were you I would used output parameters instead of return values because,
1-return values just could return integers,
2-return values just return one value,

software engineering student.
Looking for a good job for summer 2005.

Similar Threads
Thread Thread Starter Forum Replies Last Post
stored procedure prashant_telkar SQL Server 2000 1 July 9th, 2007 07:57 AM
Stored Procedure jezywrap SQL Server ASP 1 January 3rd, 2007 12:29 AM
stored procedure kdm260 SQL Server 2000 2 June 19th, 2006 04:45 PM
Stored Procedure rajanikrishna SQL Server 2000 0 July 18th, 2005 05:01 AM
Help About Stored Procedure zhuge6 BOOK: ASP.NET Website Programming Problem-Design-Solution 3 May 20th, 2005 09:27 AM

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