Hi,
I'm workin on a website where i need to update a password using a stored procedure. I tested the stored procedure on SQL server and its working fine. but somehow i cannot seem to call it from C#. Can any one please help me?
Stored Procedure
CREATE PROCEDURE dbo.sp_ChangePassword
(
@Password VARCHAR(50),
@newPassword VARCHAR(50),
@Username VARCHAR(50)
)
AS
UPDATE Login SET Password = @newPassword
WHERE UserName = @UserName AND Password = @Password
RETURN
Code in c#
SqlConnection conn = new SqlConnection(@"Data Source=R2\SQLEXPRESS;Initial Catalog=Student;Integrated Security=True");
SqlCommand chpass = new SqlCommand("sp_ChangePassword",conn);
chpass.CommandType = CommandType.StoredProcedure;
chpass.Connection = conn;
SqlParameter usr_param = chpass.Parameters.Add("@Username", SqlDbType.VarChar);
SqlParameter currp_param = chpass.Parameters.Add("@Password", SqlDbType.VarChar);
SqlParameter newpass_param = chpass.Parameters.Add("@newPassword", SqlDbType.VarChar);
usr_param.Direction = ParameterDirection.Input;
currp_param.Direction = ParameterDirection.Input;
newpass_param.Direction = ParameterDirection.Input;
usr_param.Value = Piname.Text;
currp_param.Value = currpass.Text;
newpass_param.Value = newpass.Text;
try
{
chpass.ExecuteNonQuery();
errLabel.Text = "Password Sucessfully Changed";
}catch(Exception exp){errLabel.Text=exp.message;}