Reputation: 117
Procedure or function 'login' expects parameter '@Abc', which was not supplied
4 hours searching and trying and no use I already supplied this parameter (copy/paste) and the number of parameters given to procedure is the same of procedure and in order.
@Abc is an output parameter.
Stored procedure definition:
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
ALTER proc [dbo].[login]
(
@Abc int output,
@firstname varchar(255) output,
@lastname varchar(255) output,
@Email varchar(255),
@pass varchar(255)
)
As
begin
if not exists (select Email from user_1 where email=@email)
select @Abc = 0
else begin
if not exists (
select Email from user_1 where email =@Email and password = @pass
)
select @Abc = 1
else
select @Abc = 2,@firstname = u.first_name ,@lastname=u.last_name from user_1 u where u.email = @email
end
end
Code to call the stored procedure:
myCon.Open();
TextBox username = UserName;
TextBox password = Password;
SqlCommand myCommand = new SqlCommand("login", myCon);
SqlParameter count= myCommand.Parameters.Add("@Abc", SqlDbType.Int);
count.Direction = ParameterDirection.Output;
SqlParameter fnp = myCommand.Parameters.Add("@firstname", SqlDbType.VarChar,255);
fnp.Direction = ParameterDirection.Output;
SqlParameter lnp = myCommand.Parameters.Add("@lastname", SqlDbType.VarChar, 255);
lnp.Direction = ParameterDirection.Output;
myCommand.Parameters.AddWithValue("@Email",username.Text);
myCommand.Parameters.AddWithValue("@pass", password.Text);
myCommand.ExecuteNonQuery();
myCon.Close();
Upvotes: 2
Views: 4245
Reputation: 175748
You have omitted:
myCommand.CommandType = CommandType.StoredProcedure;
So the command sent to the DB is a malfed sp_executeSQL
call instead of the desired exec login
FYI there is also a shorter syntax:
myCommand.Parameters.Add("@Abc", SqlDbType.Int).Direction = ParameterDirection.Output;
Upvotes: 6