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:
command.Parameters.Add(@username,SqlDbType.VarChar,50).Value=username;
command.Parameters.Add(@password, SqlDbType.VarChar,50).Value=password;
with:
command.Parameters.Add("@Username",SqlDbType.VarChar,50).Value=username;
command.Parameters.Add("@Password", SqlDbType.VarChar,50).Value=password;
You need to put your parameter name in quotes for the Add method. In other words, "@username" with the quotes.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With