Gives solution for any Error occurs in any Programming Language, .Net Core 3.1, 3.0, C#,Asp.Net,Sqlserver,MVC,Java,Php,Html,Css,Jquery,errors and solutions,Latest News,Technology

Wednesday, 2 December 2015

How to execute stored procudure With an output Parameter in C# and Sql Server

No comments :
CREATE PROCEDURE SAMLE @input  VARCHAR(20),
                       @output VARCHAR(20) output
AS
  BEGIN
      IF @input >= '1'
        BEGIN
            SET @output = 'HI';

            RETURN;
        END
  END
Executtion
DECLARE @get VARCHAR(20);
EXEC testme-Procedure Name
  '1',
  @get output

SELECT @get 
C# Code:
SqlCommand cmdStoredProcedure = new SqlCommand();
cmdStoredProcedure.CommandText = "procedure name";
cmdStoredProcedure.CommandType = CommandType.StoredProcedure;
cmdStoredProcedure.Parameters.Add("parmater1", SqlDbType.VarChar, 50);
cmdStoredProcedure.Parameters.Add("parmater2", SqlDbType.VarChar, 500).Direction = ParameterDirection.Output;
// set parameter values
cmdStoredProcedure.Parameters["paramter"].Value = "1";
cmdStoredProcedure = SchedulerJobBLL.ExecuteSQLSP(connectionstring, cmdStoredProcedure);
cmd.Parameters["paramter2"].Value.ToString();

No comments :

Post a Comment