Click here to Skip to main content
16,004,882 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I have created sp in sql server 2012.Sp have output para of type varchar(15).

create procedure [dbo].[Proc_Authenticate]

    (
           @username int,   
           @password varchar(25),
           @Error varchar(15) output
    )

AS

    BEGIN 

        Declare @count int

        set @count = (select count(*) from loginmaster where userid = @userid and password = @password)

        if(@count = 0)

        begin
            Set @Error = 'Error1'
        end

    END


when I run sp from sql,it is working properly but when I using/calling sp from C#,with the help of executescalar,not working as expected.Executescalar always return null.If the same same thing I do with ExecuteNonquery,it is working properly.Executenonquery is used for insertion/updation.Exeutenonquery return number of row affected.i.e is int value. Int rowaffected = cmd.ExecuteNonquery() Normally I check if rowaffected is greater than 0,take value output para.

if(rowaffected  > 0)
{
  string s = sqlparameterError.value.Tostring()
}


Here How I check,rowaffected is always -1.Is it right way to check it?

What I have tried:

create procedure [dbo].[Proc_Authenticate]

    (
           @username int,   
           @password varchar(25),
           @Error varchar(15) output
    )

AS

    BEGIN 

        Declare @count int

        set @count = (select count(*) from loginmaster where userid = @userid and password = @password)

        if(@count = 0)

        begin
            Set @Error = 'Error1'
        end

    END
Posted
Updated 17-Jan-17 20:15pm

1 solution

In your .net application you will have to set parameter direction, some thing like cmd.Parameters["ParamName"].Direction = ParameterDirection.Output;

You can have look at How to return Output parameter from Stored Procedure in ASP.Net using C# and VB.Net[^]
 
Share this answer
 

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