3
Reply

how to update userid and password using c# windowsform

Sheffer Fernandes

Sheffer Fernandes

Jan 18 2015 1:43 AM
599
hi guys im a new bie in programming and im maiking a project in which i want the user to be ableto change hes user id and password but im nt able to do it ,can ull plz help
this is my code:

private void button1_Click(object sender, EventArgs e)
  {
  try
  {
  OleDbCommand command = new OleDbCommand();

  string query = "select UserName from UserTable  where Password='"+ textBox2.Text +"'";

  command.CommandText = query;

  OleDbDataReader reader = command.ExecuteReader();

  if (reader.Read())
  {
  // string a= Convert.ToString(textBox1.Text);
  //string b = Convert.ToString(textBox2.Text);

  string UserName=reader["UserName"].ToString();
  string Password = reader["Password_U"].ToString();

  if (textBox1.Text== UserName)
  {
  connect.Open();
  command.CommandText = "update UserTable set UserName ='" + textBox4.Text + "'"; //where ManagerName = [Julius Fernandes]";

  command.ExecuteNonQuery();
  connect.Close();
 
  }

  if (textBox2.Text == Password)
  {
  connect.Open();
  command.CommandText = "update UserTable set Password_U ='" + textBox5.Text + "'";// where ManagerName = [Julius Fernandes]";

  command.ExecuteNonQuery();
  connect.Close();
 
  }
 
  }
  }

  catch (Exception ex)
  {
  MessageBox.Show("Invalid UserId or Password,Please Fill the Fields Correctly" + ex);
  connect.Close();

  }
  }
  }
}

Answers (3)