0

Ok so I have a class called DBdatabase.cs which stored all my sql queryies, what I am trying to do is execute an update statement that updates the users password through the session however when I execute the statement nothing occurs what am I doing wrong?

Also Please note that the update statment does work when I have the sql statment in ChangePassword.aspx.cs as I declare the session state in the sql statment like this 'Session["LoginSession1"]'.

Code below:

DBdatabase.cs

public static void ChangePasswordParent(string password, object session)
        {

            cmd = new SqlCommand("UPDATE Users SET Password ='" + password + "' WHERE Username = '" + session + "'", con);


            try
            {
                con.Open();
                cmd.ExecuteNonQuery();
            }
            catch (Exception ex)
            {
                Console.WriteLine("Exception in DBHandler", ex);
            }
            finally
            {
                con.Close();
            }
        }

Changepassword.aspx.cs

 if (Session["LoginSession"] != null)
                    {

                        string a = TextBox3.Text;
                        object b = Session["LoginSession1"];

                        DBdatabase.ChangePasswordParent(a,b);
                        Label4.Text = "Password Changed";
                        this.Label4.ForeColor = Color.Green;

                    }
1
Contributor
1
Reply
2
Views
4 Years
Discussion Span
Last Post by TIM_M_91
0

I made a silly mistake needed to do this:

public static void ChangePasswordParent(string password, string b)

and:

string b = Session["LoginSession"].ToString();
This question has already been answered. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.