Note that there are some explanatory texts on larger screens.

plurals
  1. POTable is not getting updated , when used executeNonquery
    primarykey
    data
    text
    <p>I am trying to change the user password. I am not able to update the password :(. The message i am getting is password changed where as its not getting changed. . My code is as follow.. Please if anyone can suggest where i am going wrong . I am just a beginner ...</p> <pre><code>protected void Button1_Click(object sender, EventArgs e) { DatabaseLayer data = new DatabaseLayer(); string username = Session["Authenticate"].ToString(); string password = TextBox1.Text; string newpass = TextBox2.Text; string confirm = TextBox3.Text; string flag = ""; if (newpass.ToString() == confirm.ToString()) { flag = data.passwordChange(username, password, newpass); Literal1.Text = flag.ToString(); } else { Literal1.Text = "New Password does not match the Confirm Password "; } } </code></pre> <p>The above click event must change my password, and the function passwordChange is as follows..</p> <pre><code>public string passwordChange(string username, string password, string newPasswd) { string SQLQuery = "SELECT password FROM LoginAccount WHERE username = '" + username + "'"; string SQLQuery1 = "UPDATE LoginAccount SET password = ' " + newPasswd + " ' WHERE username = ' " + username + "'"; SqlCommand command = new SqlCommand(SQLQuery, sqlConnection); SqlCommand command1 = new SqlCommand(SQLQuery1, sqlConnection); sqlConnection.Open(); string sqlPassword = ""; SqlDataReader reader; try { reader = command.ExecuteReader(); if (reader.Read()) { if (!reader.IsDBNull(0)) { sqlPassword = reader["password"].ToString(); } } reader.Close(); if (sqlPassword.ToString() == password.ToString()) { try { int flag = 0; flag = command1.ExecuteNonQuery(); if (flag &gt; 0) { sqlConnection.Close(); return "Password Changed Successfully"; } else { sqlConnection.Close(); return "User Password could not be changed"; } } catch (Exception exr) { sqlConnection.Close(); return "Password Could Not Be Changed Please Try Again"; } } else { sqlConnection.Close(); return "User Password does not Match"; } } catch (Exception exr) { sqlConnection.Close(); return "User's Password already exists"; } } </code></pre> <p>I had put a break point near </p> <pre><code>if(flag&gt;0) </code></pre> <p>it still shows that executeNonquery aint returning the updated rows value and also in the Back end of SQL server, its not changing, Please if anyone could correct me... Should i use other execute command or something? I am doing this with VS 2008 and SQL server 2005..</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload