473,404 Members | 2,137 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,404 software developers and data experts.

How to get the returned value from Stored Proc. ?

Hi,

I have a stored procedure (ms sql 2005) which is return add
the user in the table USERS. But the sp (stored proc) tests
if a user with the desired nickname already exists. If
exists, return -1 otherwise return 1 and execute the INSERT
query!

But, how to get the returned value from the stored
procedure (called : CreateAccount) in ASP.NET ?

My actual code :
__________
SqlCommand myCommand = new SqlCommand();
String strCnx =
ConfigurationSettings.ConnectionStrings["AppCnxStr"].ConnectionString.ToString();
myCommand.Connection = new SqlConnection(strCnx);
myCommand.Connection.Open();

SqlParameter myNickname = new SqlParameter("@Nickname",
SqlDbType.NVarChar, 30);
myNickname.Value = boxLogin.Text;
myCommand.Parameters.Add(myNickname);
.... // same for all parameters.

myCommand.ExecuteNonQuery();

// here i want to get the value to make an if : if (value =
1) COMPLETE REGISTRATION else GO BACK TO CHANGE NICKNAME.
________________________

Regards.
Nov 18 '05 #1
2 1516
The .ExecuteScalarm method of the SqlCommand object is designed to return a
single value... something like this

int retVal = Convert.ToInt32(myCommand.ExecuteScalar());

"Jiggaz" <an*******@discussions.microsoft.com> wrote in message
news:29*****************************@phx.gbl...
Hi,

I have a stored procedure (ms sql 2005) which is return add
the user in the table USERS. But the sp (stored proc) tests
if a user with the desired nickname already exists. If
exists, return -1 otherwise return 1 and execute the INSERT
query!

But, how to get the returned value from the stored
procedure (called : CreateAccount) in ASP.NET ?

My actual code :
__________
SqlCommand myCommand = new SqlCommand();
String strCnx =
ConfigurationSettings.ConnectionStrings["AppCnxStr"].ConnectionString.ToStri
ng();
myCommand.Connection = new SqlConnection(strCnx);
myCommand.Connection.Open();

SqlParameter myNickname = new SqlParameter("@Nickname",
SqlDbType.NVarChar, 30);
myNickname.Value = boxLogin.Text;
myCommand.Parameters.Add(myNickname);
.... // same for all parameters.

myCommand.ExecuteNonQuery();

// here i want to get the value to make an if : if (value =
1) COMPLETE REGISTRATION else GO BACK TO CHANGE NICKNAME.
________________________

Regards.
Nov 18 '05 #2
You could also use the SqlParameter class and have the stored procedure
return the value (ParameterDirection.Output). Just another option.

Todd Casey
Velocity West

"Robert Howells" <A@B.com> wrote in message
news:ee**************@TK2MSFTNGP11.phx.gbl...
The .ExecuteScalarm method of the SqlCommand object is designed to return
a
single value... something like this

int retVal = Convert.ToInt32(myCommand.ExecuteScalar());

"Jiggaz" <an*******@discussions.microsoft.com> wrote in message
news:29*****************************@phx.gbl...
Hi,

I have a stored procedure (ms sql 2005) which is return add
the user in the table USERS. But the sp (stored proc) tests
if a user with the desired nickname already exists. If
exists, return -1 otherwise return 1 and execute the INSERT
query!

But, how to get the returned value from the stored
procedure (called : CreateAccount) in ASP.NET ?

My actual code :
__________
SqlCommand myCommand = new SqlCommand();
String strCnx =
ConfigurationSettings.ConnectionStrings["AppCnxStr"].ConnectionString.ToStri
ng();
myCommand.Connection = new SqlConnection(strCnx);
myCommand.Connection.Open();

SqlParameter myNickname = new SqlParameter("@Nickname",
SqlDbType.NVarChar, 30);
myNickname.Value = boxLogin.Text;
myCommand.Parameters.Add(myNickname);
... // same for all parameters.

myCommand.ExecuteNonQuery();

// here i want to get the value to make an if : if (value =
1) COMPLETE REGISTRATION else GO BACK TO CHANGE NICKNAME.
________________________

Regards.

Nov 18 '05 #3

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

Similar topics

6
by: CJM | last post by:
I've created a Stored Procedure which adds a new record and updates some more records and then returns the primary key for the added record. The SP seems to work OK, but I'm having problems...
5
by: Raquel | last post by:
This is a very simple DB2 SQLJ stored procedure. The problem is that it seems to run fine but returns NOTHING. I mean..as if nothing has happened..not resultset is returned. I am passing value...
6
by: Max | last post by:
Anyone know why I'm always getting 0 returned? My stored procedure returns -1. Dim iErrorCode As Int32 iErrorCode = Convert.ToInt32(SqlHelper.ExecuteScalar(AppVars.strConn, _ "gpUpdateMember",...
4
by: Learner | last post by:
Hi there, I have a storec proc that schedules a Sql job and finally it returns 0 then it was successfull and if it returns 1 then its unsuccessful. Now when i run the stored proc in the query...
1
by: Phil Mc | last post by:
Trying to call a stored proc but some times don't want to have values inserted in some fields. Hi I am rewriting a VBS script which called a stored proc in a SQL server db. The proc takes a...
3
by: keithb | last post by:
What can I put in a stored procedure to control what gets returned by command.ExecuteNonQuery()? I already tried this: param = comm.CreateParameter(); param.ParameterName = "@Success"; ...
1
by: Gazchurchend | last post by:
Hi I have been trying to use stored procedures in PHP as shown in the example below. But all the ones I have tried return strange values. This simple function simply returns a user id given their...
2
by: =?Utf-8?B?Vmlua2k=?= | last post by:
Hello Everyone, I can successfully insert and update the oracle database by calling a oracles stored proc from my .net code. This oracle stored proc is returning some value. I cannot see that...
1
by: =?Utf-8?B?Vmlua2k=?= | last post by:
Hello Everyone, I can successfully insert and update the oracle database by calling a oracles stored proc from my .net code. This oracle stored proc is returning some value. I cannot see that...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
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,...
0
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...
0
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...
0
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...
0
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,...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

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.