473,503 Members | 1,797 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

How do I get an output Parameters value from a stored procedure

487 Recognized Expert Contributor
I am trying to get an output Parameters value from a stored procedure using
sqlDataSource in asp.net 2.0. But I only get a null value for the
output Parameters. Can someone Point me to get value?

Expand|Select|Wrap|Line Numbers
  1.         SqlDataSource InsertDS = getSqlDataSource;
  2. //-----------------parameters
  3.         InsertDS.InsertParameters.Add("FirstName", FirstName);
  4.         .......................................
  5. //----------------This is an Output Param
  6.         InsertDS.InsertParameters.Add("outQryStatus", strOutStatus);
  7.         InsertDS.InsertCommand = "RegisterUser";
  8.         try{
  9.             intRowsAffected = InsertDS.Insert();
  10. //-------------Trying to get and return
  11.             return InsertDS.InsertParameters[7].DefaultValue.ToString();
  12. //-----------------And also tyried 
  13.            //return strOutStatus; //this also return null
  14.         }
  15.         catch ........Block
  16.         ..........................................
  17.  
Note: I am using it in my Webservice.cs.
May 8 '08 #1
5 2589
Plater
7,872 Recognized Expert Expert
It doesn't look like you're designating your parameter's direction as output.

For example:
Expand|Select|Wrap|Line Numbers
  1. SqlCommand sc = new SqlCommand("AddNewBillOfMaterialsConnections", dbcon);
  2. sc.CommandType = CommandType.StoredProcedure;
  3.  
  4. sc.Parameters.Add("@PartID", SqlDbType.BigInt);
  5. sc.Parameters["@PartID"].Value = PartID;
  6.  
  7. sc.Parameters.Add("@Notes", SqlDbType.VarChar);
  8. sc.Parameters["@Notes"].Value = quoteReplace(Notes);
  9.  
  10. sc.Parameters.Add("@ModifiedDate", SqlDbType.DateTime);
  11. sc.Parameters["@ModifiedDate"].Value = ModifiedDate;
  12.  
  13. //out
  14. sc.Parameters.Add("@BOMConnectionID", SqlDbType.BigInt);
  15. sc.Parameters["@BOMConnectionID"].Direction = ParameterDirection.Output;
  16.  
  17. sc.ExecuteNonQuery();
  18. Int64 retval = (Int64)sc.Parameters["@BOMConnectionID"].Value;
  19. sc.Dispose();
  20.  
May 8 '08 #2
CyberSoftHari
487 Recognized Expert Contributor
Working fine with SqlCommand (i chang it in my code). How to do it in SqlDataSource?
Thank you.
May 9 '08 #3
Plater
7,872 Recognized Expert Expert
I think you can do:
InsertDS.InsertParameters["paramName"].Direction = ParameterDirection.Output;
May 9 '08 #4
CyberSoftHari
487 Recognized Expert Contributor
Thank you plater, I feel SqlCommand is easer than SqlDataSource.
In SqlDS we need to use Different properties for Insert, Update, Delete and Select query commands.
May 9 '08 #5
Plater
7,872 Recognized Expert Expert
The SqlDataSource's Insert/Update/Delete are just instances of the SqlCommand object. the difference is, they get called automatically with special setups to handle the data in your datasource.
May 9 '08 #6

Sign in to post your reply or Sign up for a free account.

Similar topics

5
8253
by: Steve Holden | last post by:
Has anyone, with any driver whatsoever, managed to retrieve output parameters from a SQL Server stored procedure? I've just been rather embarrassed to find out it's not as easy as it might seem,...
4
2175
by: Steven | last post by:
I'm calling a stored procedure which has an output parameter of type int. Once the stored procedure is executed, I want to check the value of the parameter in case it is null. However, when the a...
4
45055
by: laurenq uantrell | last post by:
I need to get the value of an output parameter back into my VBA function calling a stored procedure. I'm using the following construction to append a new record in a SQL Server table: ...
8
4439
by: Christopher Weaver | last post by:
I'm having trouble accessing the value of an output parameter of a stored procedure. The SP looks like this: SET TERM ^ ; CREATE PROCEDURE SP_NEW_TASK RETURNS ( "uidTask" INTEGER) AS begin
3
1348
by: James Brett | last post by:
Hi I've got this function that executes a stored procedure. One of the parameters is an output parameter but for some reason it always returns 0. Any clues? Cheers James
4
50385
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...
1
5677
by: stjulian | last post by:
If inside a stored procedure, there a SELECT statement to return a recordset and another SELECT to set the value of an output parameter (as in SELECT @OutValue = Name FROM table WHERE pkid=5),...
4
1668
by: Tifer | last post by:
Hello, I'm still new to the whole .Net thing and I'm having a problem with something that should be so simple -- executing a query and returning an output parameter. It's a standard "Add"...
1
1894
by: Arpan | last post by:
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...
3
5089
by: leesquare | last post by:
Hello, I need some help getting output values from my stored procedures when using adodbapi. There's an example testVariableReturningStoredProcedure in adodbapitest.py, and that works for my...
0
7199
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
7076
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
7274
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
1
5005
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...
0
4670
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...
0
3162
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...
0
1507
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...
1
732
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
0
377
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...

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.