473,835 Members | 1,841 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Output Parameter?

A SQL Server 2005 DB table named "Users" has the following columns:

ID - int (IDENTITY)
FirstName - varchar(50)
LastName - varchar(50)
UserID - varchar(20)
Password - varchar(20)

Before inserting a new record in the DB table, ASP.NET first checks
whether the UserID supplied by the new record already exists or not. If
it exists, the new record shouldn't be inserted in the DB table & the
user should be shown a message saying "UserID already exists". To do
this, ASP.NET uses a stored procedure. If the value returned by the
stored procedure is 1, it means that the UserID already exists. If the
value returned by the stored procedure is 0, then the new record should
be inserted in the DB table. This is how I have framed the stored
procedure:

CREATE PROCEDURE RegisterUsers
@FName varchar(50),
@LName varchar(50),
@UserID varchar(50),
@Password varchar(50),
@return_value int OUTPUT
AS
IF EXISTS(SELECT UserID FROM Users WHERE UserID=@UserID)
BEGIN
SET @return_value=1
END
ELSE
BEGIN
SET @return_value=0
INSERT INTO Users VALUES (@FName,@LName, @UserID,@Passwo rd)
END

& this is how I am invoking the stored procedure in the ASPX page:

<script runat="server">
Sub btnSubmit(ByVal obj As Object, ByVal ea As EventArgs)
Dim sqlCmd As SqlCommand
Dim sqlConn As SqlConnection

sqlConn = New SqlConnection(" Data
Source=MyDB\SQL EXPRESS;Initial Catalog=DB;Inte grated Security=True")
sqlCmd = New SqlCommand("Reg isterUsers", sqlConn)
sqlCmd.CommandT ype = CommandType.Sto redProcedure

With sqlCmd
Parameters.Add( "@return_value" , SqlDbType.Int, 4).Direction
= ParameterDirect ion.ReturnValue
Parameters.AddW ithValue("@FNam e", txtFName.Text)
Parameters.AddW ithValue("@LNam e", txtLName.Text)
Parameters.AddW ithValue("@User ID", txtUserID.Text)
Parameters.AddW ithValue("@Pass word", txtPassword.Tex t)
End With

sqlConn.Open()
sqlCmd.ExecuteN onQuery()

If (sqlCmd.Paramet ers(0).Value = 1) Then
lblMessage.Text = "UserID Already Exists!"
ElseIf (sqlCmd.Paramet ers(0).Value = 0) Then
lblMessage.Text = "Thank You For Registering
End If

sqlConn.Close()
End Sub
</script>
<form runat="server">
<%-- the 4 TextBoxes come here -->
</form>

When I execute the above ASPX code, if the UserID I entered already
exists in the DB table, then ASPX generates the following error:

Procedure or Function 'RegisterUsers' expects parameter
'@return_value' , which was not supplied.

pointing to the line

sqlCmd.ExecuteN onQuery()

Can someone please point out where am I going wrong?

Thanks,

Arpan

Aug 25 '06 #1
1 1904
Type is output, not returnvalue.

--
Gregory A. Beamer
MVP; MCP: +I, SE, SD, DBA

*************** *************** *************** ****
Think outside of the box!
*************** *************** *************** ****
"Arpan" <ar******@hotma il.comwrote in message
news:11******** *************@i 3g2000cwc.googl egroups.com...
>A SQL Server 2005 DB table named "Users" has the following columns:

ID - int (IDENTITY)
FirstName - varchar(50)
LastName - varchar(50)
UserID - varchar(20)
Password - varchar(20)

Before inserting a new record in the DB table, ASP.NET first checks
whether the UserID supplied by the new record already exists or not. If
it exists, the new record shouldn't be inserted in the DB table & the
user should be shown a message saying "UserID already exists". To do
this, ASP.NET uses a stored procedure. If the value returned by the
stored procedure is 1, it means that the UserID already exists. If the
value returned by the stored procedure is 0, then the new record should
be inserted in the DB table. This is how I have framed the stored
procedure:

CREATE PROCEDURE RegisterUsers
@FName varchar(50),
@LName varchar(50),
@UserID varchar(50),
@Password varchar(50),
@return_value int OUTPUT
AS
IF EXISTS(SELECT UserID FROM Users WHERE UserID=@UserID)
BEGIN
SET @return_value=1
END
ELSE
BEGIN
SET @return_value=0
INSERT INTO Users VALUES (@FName,@LName, @UserID,@Passwo rd)
END

& this is how I am invoking the stored procedure in the ASPX page:

<script runat="server">
Sub btnSubmit(ByVal obj As Object, ByVal ea As EventArgs)
Dim sqlCmd As SqlCommand
Dim sqlConn As SqlConnection

sqlConn = New SqlConnection(" Data
Source=MyDB\SQL EXPRESS;Initial Catalog=DB;Inte grated Security=True")
sqlCmd = New SqlCommand("Reg isterUsers", sqlConn)
sqlCmd.CommandT ype = CommandType.Sto redProcedure

With sqlCmd
Parameters.Add( "@return_value" , SqlDbType.Int, 4).Direction
= ParameterDirect ion.ReturnValue
Parameters.AddW ithValue("@FNam e", txtFName.Text)
Parameters.AddW ithValue("@LNam e", txtLName.Text)
Parameters.AddW ithValue("@User ID", txtUserID.Text)
Parameters.AddW ithValue("@Pass word", txtPassword.Tex t)
End With

sqlConn.Open()
sqlCmd.ExecuteN onQuery()

If (sqlCmd.Paramet ers(0).Value = 1) Then
lblMessage.Text = "UserID Already Exists!"
ElseIf (sqlCmd.Paramet ers(0).Value = 0) Then
lblMessage.Text = "Thank You For Registering
End If

sqlConn.Close()
End Sub
</script>
<form runat="server">
<%-- the 4 TextBoxes come here -->
</form>

When I execute the above ASPX code, if the UserID I entered already
exists in the DB table, then ASPX generates the following error:

Procedure or Function 'RegisterUsers' expects parameter
'@return_value' , which was not supplied.

pointing to the line

sqlCmd.ExecuteN onQuery()

Can someone please point out where am I going wrong?

Thanks,

Arpan

Aug 25 '06 #2

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

7
7898
by: LineVoltageHalogen | last post by:
Greetings All, I have a very large query that uses dynamic sql. The sql is very large and it requires it to be broken into three components to avoid the nvarchar(4000) issue: SET @v_SqlString( N'') SET @v_SqlString2( N'')
5
6049
by: vivienne.netherwood | last post by:
I am developing an Access Project front end with a SQL server database. I have written a stored procedure that returns a record set and also a value via an output parameter. The procedure is as follows CREATE PROCEDURE qslCheckShiftTimes @Ward NVARCHAR(6), @Shift NVARCHAR(10), @Exists TINYINT OUTPUT AS
2
2546
by: Bari Allen | last post by:
ASP Classic question: I have a Stored procedure in SQL, that works, when tested in SQL, with one input & several output parameters, as follows: CREATE PROCEDURE myProcedure @MyID int , @First varchar(80) OUTPUT , @Second varchar(80) OUTPUT , @Third varchar(80) OUTPUT , @Amount as numeric(18,0) OUTPUT
8
2016
by: Patreek | last post by:
Hi, On the line where I'm assigning RecordCount to be the value of my output parameter, I'm getting the generic "Object reference not set to an instance of an object" error. I've isolated it down to this line, as the line of code commented out just beneath it runs fine. Can anyone see why my parameter isn't an object? When I grab the command from SQL profiler and run it in Query Analyzer, I get my output parameter returned with a...
4
50419
by: Mr Not So Know It All | last post by:
im new to SQL Server and ASP.Net. Here's my problem. I have this SQL Server stored procedure with an input parameter and output parameter CREATE PROCEDURE . @in_rc varchar(8) @out_eList varchar(7) output AS select @out_eList = ecuid from _organization where rccode = @in_rc GO
0
2331
by: rockdale | last post by:
Hi, All How to get the output parameter's value when you use the SQLHelper (Microsoft Data Access Block)? When I try to access my ourput parm I got the following error. System.NullReferenceException: Object reference not set to an instance of an object. I thought it is because there is a statement cmd.Parameters.Clear() in
8
2707
by: Alec MacLean | last post by:
Hi, I'm using the DAAB Ent Lib (Jan 2006) for .NET 2.0, with VS 2005 Pro. My project is a Web app project (using the WAP add in). Background: I'm creating a survey system for our company, for which invites will target selected personnel among our customers via email. Each email will provide a custom hyperlink for each respondent using a SQL generated GUID value in the querystring. The GUID will be checked for validity before the user...
7
8565
by: ashtek | last post by:
Hi, I have a generic function that executes a stored procedure & returns a data table. Code: === public static DataTable ExecuteStoredProcedure(string strProc,SqlParameter paramArray) { SqlCommand command = new SqlCommand(strProc, connection); command.CommandType = CommandType.StoredProcedure;
1
12328
by: John Bailo | last post by:
This is a my solution to getting an Output parameter from a SqlDataSource. I have seen a few scant articles but none of them take it all the way to a solution. Hopefully this will help some poor soul. Situation: I want to do a lookup using a stored procedure for each value in a Row within a GridView. I use a lookup function in my code behind, evaluating the necessary bound fields. The problem is the SqlDataSource representing...
1
2026
by: Mike P | last post by:
I am trying to return an output parameter to my code on executing a stored procedure. In Query Analyzer, it works with no problem, but when I run my ASP code below, the output parameter never seems to return anything. Can anybody help? Dim cmdNewCampaign, rsNewCampaign, intNumber Const adCmdStoredProc = &H0004 Const adParamInput = &H0001 Const adParamOutput = &H0002 Const adVarChar = 200
0
9810
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
9653
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10526
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
10563
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
10237
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
9348
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
0
5640
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
5808
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
2
3999
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.