Change Password Of User

Last Reply 14 days ago By zameer

Posted 14 days ago

 

USE [FYP]
GO
/****** Object:  StoredProcedure [dbo].[AdminChangePassword]    Script Date: 8/8/2017 2:48:39 AM ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO

ALTER PROCEDURE [dbo].[AdminChangePassword]
(
@ID int,
@password varchar(50),
@PrevPassword varchar(10)

)
AS
BEGIN
SET NOCOUNT ON;
declare @STATUS int
if EXISTS(select * from Login where Password = @PrevPassword and ID=@ID)
	begin
		update Login set Password = @password 
       set @STATUS=1
	end
else
       set @STATUS=0
select @status end

 

public int AdminChangePassword( int ID,string password, string PrevPasswrd)
        {

            int status = 0;

            SqlCommand cmd = new SqlCommand();
            try
            {
                cmd.Connection = cn;
                cmd.CommandType = CommandType.Text;
                cn.Open();
                cmd.CommandType = CommandType.StoredProcedure;
                cmd.CommandText = "[dbo].[AdminChangePassword]";

                cmd.Parameters.Add("@ID", SqlDbType.VarChar).Value = ID;
                cmd.Parameters["@ID"].Direction = ParameterDirection.Input;
                
                cmd.Parameters.Add("@password", SqlDbType.VarChar, 50).Value = password;
                cmd.Parameters["@password"].Direction = ParameterDirection.Input;
                cmd.Parameters.Add("@PrevPassword", SqlDbType.VarChar, 50).Value = PrevPasswrd;
                cmd.Parameters["@PrevPassword"].Direction = ParameterDirection.Input;

                status = Convert.ToInt16(cmd.ExecuteScalar());

                cmd.ExecuteNonQuery();
                cn.Close();
            }
            catch (Exception)
            {
                //TextBox1.Text = string.Format("{0}",ex);
            }
            return status;

        }

 

protected void LogInBtn_ServerClick(object sender, EventArgs e)
        {

            int ID = Convert.ToInt32((Session["ID"])); 
            // string ID = Convert.ToString(Session["ID"]);
            // var ID= Convert.ToInt32((Session["ID"]));
            if (NewPassword.Value != "" && ConfirmAdminPasswrd.Value != "")
            {
                if (NewPassword.Value == ConfirmAdminPasswrd.Value)
                {
                    d.AdminChangePassword( ID, NewPassword.Value, PrevisAdminPasswrd.Value);//yha
                    Response.Redirect("LogIn.aspx");
                }

            }
        }

me trying to change the password of user but error occur at red line that input string was not in correct format.Kindly help me to resolve this

 

You are viewing reply posted by: zameer 14 days ago.
Posted 14 days ago

Hi Sonam,

Use the debugger, you dont need to comment the red line just set the breakpoint at that line and start debugging you will come to know  the value of ID 

I agree, here is the link: https://www.e-iceblue.com/Introduce/spire-office-for-net-free.html