ADO/ADO.NET - cmd = new OleDbCommand("update changepass set password = '" + npass + "' where username

Asked By rohit bansal on 29-Jun-12 01:34 AM
  cmd = new OleDbCommand("update  changepass set password = '" + npass + "' where username = '" + TextBox1.Text + "'", con);
            cmd.ExecuteNonQuery();

pls find error

Jitendra Faye replied to rohit bansal on 29-Jun-12 02:45 AM
try like this-


OleDbConnection connection = new OleDbConnection(connectionString);
connection.Open();
OleDbCommand command = new
OleDbCommand(query, connection);
command.ExecuteNonQuery();


replace your query here.

KCH replied to rohit bansal on 29-Jun-12 03:30 AM
hi,,,,
Your query is correct...here password,username   should match the table columns...check spell once...

dipa ahuja replied to rohit bansal on 29-Jun-12 09:52 AM
Try this proper code for changing password protected void Button1_Click(object sender, EventArgs e)
{
  //first check user is logged in or session is expired
  if (Session["user"] != null)
  {
    if (txtoldPassword.Text == txtNewPassword.Text)
    {
      Response.Write("<script>alert('your old passwod is same as new pass')</script>");
      return;
    }
    else
    {
      string user = Session["user"].ToString();
      SqlConnection conn = new SqlConnection("connectionString");
      string q = "Update users set password='" + txtNewPassword.Text
        + "' where username='" + user + "' and password='" + txtoldPassword.Text + "'";
 
      conn.Open();
      SqlCommand comm = new SqlCommand(q, conn);
      comm.ExecuteNonQuery();
      Response.Write("<script>alert('password changed')</script>");
      conn.Close();
    }
  }
  else
  {
    //if not logged in
    Response.Redirect("login.aspx");
  }
}