this is a piece of code from a register app which uses databases.Since i can say i know the basic principles of OOP , I understand this code EXCEPT FOR THE FIRST LINE. How can an object (reader) be a method(ExecuteReader()) of another object (cmd1) from another class(SqlCommand)? I expected that the only way i can create an object is by writing sth like this: (class object = new class()). A link where this to be explained would be welcomed too.
using(SqlDataReader reader = cmd1.ExecuteReader())
{
if (reader.Read())
{
reader.Close();
if (textBox4.Text == textBox5.Text)
{
using (SqlCommand cmd = new SqlCommand("UPDATE info SET Password=@Password WHERE Id=@Id AND Password=@Password1", conn))
{
cmd.Parameters.AddWithValue("@Password", textBox4.Text);
cmd.Parameters.AddWithValue("@Id", textBox3.Text);
cmd.Parameters.AddWithValue("@Password1", textBox2.Text);
cmd.ExecuteNonQuery();
}
MessageBox.Show("Password has been changed");
}
else
MessageBox.Show("The new password doesn't match the one written in repeat the new password blank space ");
}
else
MessageBox.Show("Wrong Id or Password");
}