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;

                    }

I made a silly mistake needed to do this:

public static void ChangePasswordParent(string password, string b)

and:

string b = Session["LoginSession"].ToString();
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.