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