User Name Password Register
DaniWeb IT Discussion Community
All
What is DaniWeb IT Discussion Community?
You're currently browsing the ASP.NET section within the Web Development category of DaniWeb, a massive community of 456,556 software developers, web developers, Internet marketers, and tech gurus who are all enthusiastic about making contacts, networking, and learning from each other. In fact, there are 3,456 IT professionals currently interacting right now! Registration is free, only takes a minute and lets you enjoy all of the interactive features of the site.
Please support our ASP.NET advertiser: Lunarpages ASP Web Hosting
Views: 5199 | Replies: 2 | Solved
Reply
Join Date: Aug 2007
Posts: 57
Reputation: rrocket is an unknown quantity at this point 
Rep Power: 2
Solved Threads: 0
rrocket's Avatar
rrocket rrocket is offline Offline
Junior Poster in Training

Help Return value from Stored Procedure to TextBox

  #1  
Oct 17th, 2007
I am trying to get a value from a stored procedure:
  1. SET @RowCount = @@RowCount
  2. IF @RowCount = 1 BEGIN SET @Ret = 1 PRINT 'Insert a success' END
  3. IF isnull(@RowCount,0) = 0 BEGIN SET @Ret = 2 PRINT 'Insert a failure.. Terminating Proc...' RETURN END

I should be getting a 1 or 2, but keep getting a 0 with this code:
  1. cmd.Parameters.Add("@Ret", SqlDbType.Int);
  2. cmd.Parameters["@Ret"].Direction = ParameterDirection.ReturnValue;
  3. conn.Open();
  4. int ReturnedVal=1;
  5. cmd.ExecuteNonQuery();
  6. ReturnedVal = (int)cmd.Parameters["@Ret"].Value;
  7. conn.Close();
  8. CountCheck.Text = Convert.ToString(ReturnedVal);

I would really like to get the printed statements, but will settle for anything at this point.
AddThis Social Bookmark Button
Reply With Quote  
Join Date: Oct 2007
Posts: 3
Reputation: Roxion is an unknown quantity at this point 
Rep Power: 0
Solved Threads: 2
Roxion Roxion is offline Offline
Newbie Poster

Re: Return value from Stored Procedure to TextBox

  #2  
Oct 18th, 2007
which version do you use asp.net 2.0?
Reply With Quote  
Join Date: Aug 2007
Posts: 57
Reputation: rrocket is an unknown quantity at this point 
Rep Power: 2
Solved Threads: 0
rrocket's Avatar
rrocket rrocket is offline Offline
Junior Poster in Training

Re: Return value from Stored Procedure to TextBox

  #3  
Oct 18th, 2007
Thanks for responding... I am using 2.0 and actually got what I needed from another forum, but if you have any other comments let me know... The initial issue was solved by adding the @Ret after the RETURN in the if statements.

Here is the solution:
  1. SET @RowCount = @@RowCount
  2. IF @RowCount = 1 BEGIN SET @Ret = 1 PRINT 'Insert a success' END
  3. IF isnull(@RowCount,0) = 0 BEGIN SET @Ret = 2 PRINT 'Insert a failure.. Terminating Proc...' RETURN @Ret END

  1. cmd.Parameters.Add("@Ret", SqlDbType.Int);
  2. cmd.Parameters["@Ret"].Direction = ParameterDirection.Output;
  3. cmd.Parameters.Add("@RETURN_VALUE", SqlDbType.Int);
  4. cmd.Parameters["@RETURN_VALUE"].Direction = ParameterDirection.ReturnValue;
  5. conn.Open();
  6. int ReturnedVal=1;
  7. cmd.ExecuteNonQuery();
  8. ReturnedVal = (int)cmd.Parameters["@Ret"].Value;
  9. int AlsoReturnedVal=(int)cmd.Parameters["@RETURN_VALUE"].Value;
  10. conn.Close();
  11. CountCheck.Text = Convert.ToString(ReturnedVal);
Last edited by rrocket : Oct 18th, 2007 at 1:06 pm.
Reply With Quote  
Reply

Only community members can participate in forum threads. You must register or log in to contribute.

DaniWeb ASP.NET Marketplace
Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)

 

Thread Tools Display Modes

Similar Threads
Other Threads in the ASP.NET Forum

All times are GMT -4. The time now is 5:33 am.
Forum system based on vBulletin Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
©2003 - 2008 DaniWeb® LLC