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();
}
}
}
}
Loading
Sheffer FernandesPosted Jan 19, 2015, 10:26 AM
i tired changing only the password but still getting an error
this is the code:
and this is the error:
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();
while (reader.Read())
{
// string a= Convert.ToString(textBox1.Text);
//string b = Convert.ToString(textBox2.Text);
string Password = reader["Password_U"].ToString();
if (textBox2.Text == Password)
{
connect.Open();
command.CommandText = "update UserTable set Password_U = @pass where UserName =@username";
command.Parameters.AddWithValue("pass", textBox5.Text);
command.Parameters.AddWithValue("username", textBox1.Text);
command.ExecuteNonQuery();
connect.Close();
}
}
}
catch (Exception ex)
{
MessageBox.Show("Invalid UserId or Password,Please Fill the Fields Correctly" + ex);
connect.Close();
}
}
}
}
Riddhi ValechaPosted Jan 19, 2015, 4:52 AM
Your logic is wrong dear.... Usernames must be unique.. Passwords can match...
Username must not be changed... It is a wrong practice.
Vithal WadjePosted Jan 18, 2015, 3:08 PM