Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > ASP .Net > How to get the returned value from Stored Proc. ?

Reply
Thread Tools

How to get the returned value from Stored Proc. ?

 
 
Jiggaz
Guest
Posts: n/a
 
      07-08-2004
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.
 
Reply With Quote
 
 
 
 
Robert Howells
Guest
Posts: n/a
 
      07-08-2004
The .ExecuteScalarm method of the SqlCommand object is designed to return a
single value... something like this

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



"Jiggaz" <(E-Mail Removed)> wrote in message
news:294b701c46512$c5a5ca50$(E-Mail Removed)...
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.


 
Reply With Quote
 
 
 
 
Todd Casey
Guest
Posts: n/a
 
      07-08-2004
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" <(E-Mail Removed)> wrote in message
news:(E-Mail Removed)...
> The .ExecuteScalarm method of the SqlCommand object is designed to return
> a
> single value... something like this
>
> int retVal = Convert.ToInt32(myCommand.ExecuteScalar());
>
>
>
> "Jiggaz" <(E-Mail Removed)> wrote in message
> news:294b701c46512$c5a5ca50$(E-Mail Removed)...
> 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.
>
>



 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Search through data returned from stored procedure CSINVA ASP .Net 1 11-04-2007 09:17 AM
How to detect and recognize an error returned by Stored Procedures on SQL Server. ab ASP .Net 3 08-02-2006 01:17 PM
Get cached value returned from Select() David Thielen ASP .Net Web Controls 3 04-25-2006 12:56 AM
get an output value from a stored procedure using sqlDataSource michelle ASP .Net 3 02-14-2006 02:31 PM
Problems with records returned from Stored Proc CJM ASP General 6 09-06-2005 01:49 PM



Advertisments