Click here to Skip to main content
15,881,139 members
Please Sign up or sign in to vote.
4.00/5 (1 vote)
See more:
I have written a stored procedure through which I have passed three output parameters.
How can I retrieve these output parameter values in windows application in c#?

I tried to retrieve it through sqlparameter object but there is an error generated
'the parameter @return does not contain in parameter object'.

So please any one tell me how can I retrieve the three output parameter form c# with
SqlParameter object or SqlParameterCollection object.


SQL
Alter procedure str_com
(
@id int,
@comid int output,
@brid int output
)
as

begin
select @comid=cid,@brid=bid from t1 where id=@id
end


how can I retrieve @comid and @brid in c# with SqlParameter object or SqlParameterCollection Object.

thanks
Posted
Updated 28-Jan-17 23:14pm
v2

 
Share this answer
 
Comments
Joezer BH 5-Feb-13 1:31am    
The link is OK, but I'd say it's better to direct to a simple answer rather then a thread that you have to read-to-end in order to figure out what was wrong with the code of the question in the first place.
SQL
CREATE PROCEDURE [dbo].[GetFruitName]
      @FruitId INT,
      @FruitName VARCHAR(30) OUTPUT
AS
BEGIN
      SET NOCOUNT ON;
     
      SELECT @FruitName = FruitName
      FROM Fruits
      WHERE FruitId = @FruitId
END


C#
using (SqlCommand cmd = new SqlCommand("GetFruitName", con))
        {
            cmd.CommandType = CommandType.StoredProcedure;
            cmd.Parameters.AddWithValue("@FruitId", int.Parse(txtFruitId.Text.Trim()));
            cmd.Parameters.Add("@FruitName", SqlDbType.VarChar, 30);
            cmd.Parameters["@FruitName"].Direction = ParameterDirection.Output;
            con.Open();
            cmd.ExecuteNonQuery();
            con.Close();
            TextBox1.Text =cmd.Parameters["@FruitName"].Value.ToString();
        }
 
Share this answer
 
v2

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900