473,806 Members | 2,248 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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 =
ConfigurationSe ttings.Connecti onStrings["AppCnxStr"].ConnectionStri ng.ToString();
myCommand.Conne ction = new SqlConnection(s trCnx);
myCommand.Conne ction.Open();

SqlParameter myNickname = new SqlParameter("@ Nickname",
SqlDbType.NVarC har, 30);
myNickname.Valu e = boxLogin.Text;
myCommand.Param eters.Add(myNic kname);
.... // same for all parameters.

myCommand.Execu teNonQuery();

// 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 1535
The .ExecuteScalarm method of the SqlCommand object is designed to return a
single value... something like this

int retVal = Convert.ToInt32 (myCommand.Exec uteScalar());

"Jiggaz" <an*******@disc ussions.microso ft.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 =
ConfigurationSe ttings.Connecti onStrings["AppCnxStr"].ConnectionStri ng.ToStri
ng();
myCommand.Conne ction = new SqlConnection(s trCnx);
myCommand.Conne ction.Open();

SqlParameter myNickname = new SqlParameter("@ Nickname",
SqlDbType.NVarC har, 30);
myNickname.Valu e = boxLogin.Text;
myCommand.Param eters.Add(myNic kname);
.... // same for all parameters.

myCommand.Execu teNonQuery();

// 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 (ParameterDirec tion.Output). Just another option.

Todd Casey
Velocity West

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

int retVal = Convert.ToInt32 (myCommand.Exec uteScalar());

"Jiggaz" <an*******@disc ussions.microso ft.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 =
ConfigurationSe ttings.Connecti onStrings["AppCnxStr"].ConnectionStri ng.ToStri
ng();
myCommand.Conne ction = new SqlConnection(s trCnx);
myCommand.Conne ction.Open();

SqlParameter myNickname = new SqlParameter("@ Nickname",
SqlDbType.NVarC har, 30);
myNickname.Valu e = boxLogin.Text;
myCommand.Param eters.Add(myNic kname);
... // same for all parameters.

myCommand.Execu teNonQuery();

// 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
1616
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 getting at the returned key in my ASP code: "Item cannot be found in the collection corresponding to the requested name or ordinal." A common error, but in this case I can't see why... I output the SQL
5
5175
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 'D11' to :workdept and I have checked in the table that 6 rows should have returned. Any ideas why no resultset is being returned. import java.sql.*; import sqlj.runtime.*; import sqlj.runtime.ref.*; import java.io.*; // Input/Output classes
6
3507
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", _ Convert.ToInt32(lblMember_id.Text), _ -snip- -Max
4
3056
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 analyzer its returning SQLServerAgent is not currently running so it cannot be notified of this action. Stored Procedure: aisinspect.dbo.SP_ChangeInspectionDateNew
1
2339
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 number of values both char and floats. Sometime it is a requirement that the stored proc will not be given a values for some of the floats.
3
3417
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"; param.Value = Convert.ToInt32(1); param.DbType = DbType.Int32;
1
1233
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 logon details. It should return 89 but returns 24772797. I have tried different SQL type references shown i.e. SQLINT1 etc. but all do the same.... I am stuck, HELP PLEASE.... Are there other ways I should be trying. I am using PHP 5 on IIS6...
2
5711
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 value in my .net code Below is my .net code OracleParameter mbrid = new OracleParameter("RET_MBRID", OracleType.Number); mbrid.Direction = ParameterDirection.Output;
1
1840
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 value in my .net code Below is my .net code OracleParameter mbrid = new OracleParameter("RET_MBRID", OracleType.Number); mbrid.Direction = ParameterDirection.Output;
0
9718
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...
1
10370
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
10109
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
9186
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
6876
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5545
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
5678
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
2
3849
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
3008
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.