I have this stored procedure for validating login
ALTER PROCEDURE ValidateUserLogin
(
@UserName varchar (50),
@Password varchar (50)
)
AS
BEGIN
if EXISTS(SELECT * FROM AdminLogin WHERE UserName=@UserName AND Password=@Password)
select 0/*returns 0 on success*/
ELSE
select 1/*non zero otherwise*/
END
and i am calling it using the code below but i get the following exception “Procedure or Function ‘ValidateUserLogin’ expects parameter ‘@UserName’, which was not supplied.”
bool boolReturnValue = true;
SqlCommand command = new SqlCommand();
command.Connection = sqlConnection;
command.CommandType = CommandType.StoredProcedure;
command.CommandText = "ValidateUserLogin";
command.Parameters.Add(@username,SqlDbType.VarChar,50).Value=username;
command.Parameters.Add(@password, SqlDbType.VarChar,50).Value=password;
sqlConnection.Open();
try
{
command.ExecuteScalar();
boolReturnValue=Convert.ToBoolean( command.ExecuteScalar());
}
catch (Exception ex)
{
Response.Write(ex.Message);
}
and when i try to set default value for the username and password as null i get the exception
@admin is not a parameter for procedure ValidateUserLogin
//admin is the value provided for username
Change the following two lines:
with: